I'm having trouble getting my site to work after trying to implement Nginx caching.
I use Ubuntu 16.04 (xenial), Nginx (1.10.3), PHP-FPM (7.0) and WordPress.
Port 9000 (for php-fpm) is unfiltered by UFW.
Reproducing my environment
1 - setting confs:
/etc/php/7.0/fpm/pool.d/www.conf (comments omitted)
2 - 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/
3 - Server restart:
systemctl restart nginx.service
/etc/init.d/php*-fpm restart
4- Error and debug tries:
*1 connect() failed (111: Connection refused) while connecting to upstream,
client: MY_IP_ADDRESS, server: example.com, request: "GET /
HTTP/2.0", upstream: "fastcgi://127.0.0.1:9000".
The browser gives:
502 Bad Gateway nginx/1.10.3 (Ubuntu)
Debug:
/etc/init.d/php*-fpm status
brings:
● 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 Fri 2018-04-27 07:09:28 UTC; 3s ago
Process: 16336 ExecStartPre=/usr/lib/php/php7.0-fpm-checkconf (code=exited, status=0/SUCCESS)
Main PID: 16346 (php-fpm7.0)
Status: "Ready to handle connections"
My question
Why is the connection refused and my site is down?
Update for NerdOfLinux:
+ curl -I example.com
HTTP/1.1 301 Moved Permanently
Content-Type: text/html
Content-Length: 194
Connection: keep-alive
And
grep "listen" /etc/php/7.0/fpm/pool.d/www.conf | grep -v ";"
+ grep --color=auto -v ';'
+ grep --color=auto listen /etc/php/7.0/fpm/pool.d/www.conf
listen = /run/php/php7.0-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
The issue at play is a misconfiguration by you of the nginx
fastcgi_pass
directive to point at a nonexistent backend/upstream gateway.Since 14.10 (or was it 15.10, I dont remember now exactly)
php-fpm
listens on a local UNIX socket and not TCP port 9000 by default. I know this because I spearheaded the effort to make this change in Ubuntu and Debian for the defaults for FPM, and it was accepted in the packaging. And I know this is your setup because of thelisten =
line of your FPMwww.conf
which says its listening on a socket.Put
unix:/run/php/php7.0-fpm.sock
in yourfastcgi_pass
directive in thenginx
server block, and not the127.0.0.1:9000
you have. That should then allow it to work properly because the correct PHP upstream gateway is then used.check in your php-fpm pool definition which is to be found in
/etc/php/7.0/fpm/pool.d
User www-data is used to run php-fpm:
user = www-data group = www-data