I have just installed the latest Nginx with PHP7.4-fpm on a fresh Ubuntu 20.04.2 server.
I added a virtual host that has a WordPress site on it and it is loading fine but I noticed the nginx logs bombarded with errors like the following:
[error] 183472#183472: *625 connect() failed (111: Connection refused) while connecting to upstream, client: xx.xxx.xxx.xx, server: example.com, request: "GET /some-page-name/ HTTP/1.1", upstream: "fastcgi://[::1]:8001", host: "example.com", referrer: "https://example.com/"
On googling about this, I found out from the second answer on this ServerFault thread that it was because I am using an ipv6 address and that I could fix it by replacing localhost
with 127.0.0.1
in the nginx server block files since fastcgi://[::1]:8001
won't work.
I made the changes in /etc/nginx/sites-available/example.com.conf
and changed the following line:
fastcgi_pass localhost:8001;
To:
fastcgi_pass 127.0.0.1:8001;
And according to a comment on that same ServerFault answer, in /etc/nginx/sites-available/default
, I changed the following line:
listen 80 default_server;
To:
listen 0.0.0.0:80 default_server;
However, after making the above changes and restarting nginx & php7.4-fpm, if I check the PHP execution mode in my server control panel (Virtualmin), neither of the available two options FCGId
or FPM
is being used.
When I choose FPM and click save, the fastcgi_pass 127.0.0.1:8001;
line in the nginx server block file reverts back to fastcgi_pass localhost:8001;
and the above errors starts showing up again.
The listen 0.0.0.0:80 default_server;
wasn't reverted back on restarting nginx or fpm however.
How do I instruct FPM to use the ipv4 address instead of the ipv6 address?
N.B. I have tried changing listen = /run/php/php7.4-fpm.sock
to listen = 127.0.0.1:8000
in /etc/php/7.4/fpm/pool.d/www.conf
and then following the above steps but that didn't help either and the same thing happen.
P.S. This issue isn't related to the control panel I used since there are quite a few ServerFault posts and multiple forum threads online that seems to be related to this issue when they try to use PHP-FPM with a dual-stack ipv4/ipv6 setup apparently.