Failed to implement Nginx object caching – site is down

user9303970 asked:

I use Ubuntu 16.04 (xenial) with Bash (4.3.48), Nginx (1.10.3), PHP-FPM (7.0) and WordPress.

I’m having trouble getting my site to work after trying to implement Nginx object caching.

Nginx logs

nginx -t and tail /var/log/nginx/access.log bring no errors.

tail /var/log/nginx/error.log brings this error:

2018/04/12 18:17:10 [error] 12563#12563:

*7 connect() failed (111: Connection refused) while connecting to upstream, client: MY_IP_ADDRESS, server:, request: “GET /robots.txt HTTP/1.1”, upstream: “fastcgi://”

Reproducing my current state

Here are the changes I’ve made, trying to implement Nginx object caching (all current confs):

1) My nginx.conf (see end of the http{} block):

2) My default conf-file (no special change made).

3) My virtual host (see end of the first server{} block).

4) non-comment data of /etc/php/7.0/pool.d:

user = www-data
group = www-data
listen = /run/php/php7.0-fpm.sock
listen.owner = www-data = www-data
listen.allowed_clients =
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

5) My process of creating a cache dir:

mkdir -p /var/cache/nginx/fastcgi_temp/cache/
chmod 755 /var/cache/nginx/fastcgi_temp/cache/
chown www-data:www-data /var/cache/nginx/fastcgi_temp/cache/

6) Server restart:

systemctl restart nginx.service
/etc/init.d/php*-fpm restart

7) /etc/init.d/php*-fpm status:

● php7.0-fpm.service - The PHP 7.0 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.0-fpm.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2018-04-12 17:35:43 UTC; 50min ago
  Process: 12582 ExecStartPre=/usr/lib/php/php7.0-fpm-checkconf (code=exited, status=0/SUCCESS)
 Main PID: 12591 (php-fpm7.0)
   Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
    Tasks: 3
   Memory: 19.0M
      CPU: 431ms
   CGroup: /system.slice/php7.0-fpm.service
           ├─12591 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
           ├─12594 php-fpm: pool www
           └─12595 php-fpm: pool www

Apr 12 17:35:43 myMachineName systemd[1]: Starting The PHP 7.0 FastCGI Process Manager...
Apr 12 17:35:43 myMachineName systemd[1]: Started The PHP 7.0 FastCGI Process Manager.

My question

Why is the connection refused and my site is down?

Side notes

  • Port 9000 is unfiltered by my UFW firewall.

My answer:

Your php-fpm daemon is listening on a UNIX socket, but you haven’t configured nginx to connect to that socket.

You configured PHP to listen on:

listen = /run/php/php7.0-fpm.sock

But you configured nginx to connect to:


Obviously that won’t work. You need to change one or the other so that nginx connects to exactly the same endpoint that php-fpm listens on.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.