I'm having the problem that more often than not, if I go to a page on my server that uses php, I get the "502 Bad Gateway" error.
Error logs:
/var/log/nginx/error.log
shows about 3 copies of this error per minute:
2016/08/27 15:07:22 [error] 17309#0: *53554 connect() to unix:/var/run/php5-fpm.sock
failed (11: Resource temporarily unavailable) while connecting to upstream, client:
[dedicated server], server: localhost, request: "POST /xmlrpc.php HTTP/1.0",
upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: [my IP address]
The CPU load from nginx
or php5-fpm
processes is sometimes huge (in excess of 100%), but sometimes just noticeable (2%), rarely insignificant.
Here's something I see a lot of in syslog
(!):
Aug 27 15:17:21 [site] avahi-daemon[871]: Invalid response packet from host
[some IP address that isn't mine and nslookup never heard of].
Things I've tried so far:
apt-get update
- removed and reinstalled
php5
,php5-cgi
, andphp5-fpm
- made sure
apache2
is not running on my system added this to
nginx.conf
, inside ahttp {
...}
:fastcgi_buffers 8 16k; fastcgi_buffer_size 32k; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300;
ensured that the same user that runs
nginx
, owns/var/run/php5-fpm.sock
. This is the same owner referenced aslisten.owner
andlisten.group
in/etc/php5/fpm/pool.d/www.conf
.tried changing the references to that socket to a TCP/IP socket:
/etc/nginx/sites-available/default
containing the linefastcgi_pass unix:127.0.0.1:9000;
/etc/php5/fpm/pool.d/www.conf
containing the linelisten = 127.0.0.1:9000;
Since this made none of the php pages ever work, I reverted that change.
- ensured I'm not disabling PHP files in my
nginx.conf
setup. I'm not, and sometimes it works, so that can't be it.
php5-fpm setup:
I suspect it's a problem with php5 eating up memory or CPU time since (a) it often does and (b) if I don't get that 504 error, I get a very slow load time on any page using php. Here's what I think is the relevant part of the /etc/php5/fpm/pool.d/www.conf
file:
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
So: what else should I try? TIA.