Nginx 502坏网关

Nginx 502坏网关,nginx,fpm,Nginx,Fpm,我经常遇到这样的问题,如果我访问使用php的服务器页面,就会出现502坏网关错误 错误日志: /var/log/nginx/error.log每分钟显示此错误的大约3个副本: 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,

我经常遇到这样的问题,如果我访问使用php的服务器页面,就会出现502坏网关错误

错误日志:

/var/log/nginx/error.log每分钟显示此错误的大约3个副本:

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]
nginx或php5 fpm进程的CPU负载有时超过100%,但有时仅为2%,很少是微不足道的

我在syslog中看到了很多东西!:

到目前为止我已经尝试过的事情:

更新源 拆除并重新安装php5、php5 cgi和php5 fpm 确保我的系统上没有运行apache2 这将发送到http{…}中的nginx.conf:

fastcgi_缓冲器8 16k; fastcgi_缓冲区大小32k; fastcgi_connect_超时300; fastcgi_发送_超时300; fastcgi_读取超时300

确保运行nginx的用户拥有/var/run/php5-fpm.sock。这是与/etc/php5/fpm/pool.d/www.conf中引用的listen.owner和listen.group相同的所有者

已尝试将对该套接字的引用更改为TCP/IP套接字:

/etc/nginx/sites available/default包含行fastcgi_pass unix:127.0.0.1:9000; /etc/php5/fpm/pool.d/www.conf,包含listen=127.0.0.1:9000行

因为这使得所有php页面都无法工作,所以我恢复了该更改

确保我没有在nginx.conf设置中禁用PHP文件。我不是,有时它是有效的,所以那不可能。 php5 fpm设置:

我怀疑这是php5消耗内存或CPU时间的问题,因为a它经常这样做,b如果我没有得到504错误,我会在使用php的任何页面上得到非常慢的加载时间。以下是我认为是/etc/php5/fpm/pool.d/www.conf文件的相关部分:


那么:我还应该尝试什么呢?TIA.

您可以检查以下内容

1-sudo服务php5 fpm状态,如果没有运行,尝试启动该服务

2-将套接字更改为tcp/ip时,删除unix,即在/etc/nginx/sites available/default文件中,在php块中更改fastcgi_pass unix:/var/run/php5-fpm.sock;至fastcgi_pass 127.0.0.1:9000;在/etc/php5/fpm/pool.d/www.conf文件中,将listen=/var/run/php5-fpm.sock更改为listen=127.0.0.1:9000

3-尝试增加php的进程管理器,即pm.max\u children=40,pm.start\u servers=10,pm.min\u spare\u servers=5,pm.max\u spare\u servers=10

4-从nginx.conf关闭keepalive连接


5-尝试为几乎静态的内容实现,以便所有请求都不会干扰php(如果可能)。

您可以检查以下内容

1-sudo服务php5 fpm状态,如果没有运行,尝试启动该服务

2-将套接字更改为tcp/ip时,删除unix,即在/etc/nginx/sites available/default文件中,在php块中更改fastcgi_pass unix:/var/run/php5-fpm.sock;至fastcgi_pass 127.0.0.1:9000;在/etc/php5/fpm/pool.d/www.conf文件中,将listen=/var/run/php5-fpm.sock更改为listen=127.0.0.1:9000

3-尝试增加php的进程管理器,即pm.max\u children=40,pm.start\u servers=10,pm.min\u spare\u servers=5,pm.max\u spare\u servers=10

4-从nginx.conf关闭keepalive连接


5-尝试实现几乎是静态的内容,这样所有请求都不会干扰php(如果可能)。

检查1-sudo服务php5 fpm状态,2-将套接字更改为tcp/ip时删除unix,即默认->fastcgi_pass 127.0.0.1:9000,www.conf->listen 127.0.0.1:9000;3-尝试增加php的进程管理器,即pm.max_children=40,pm.start_servers=10,pm.min_spare_servers=5,pm.max_spare_servers=10 4-从nginx.conf 5关闭keepalive连接-尽可能尝试实现缓存。有效的方法是按照您指定的pm.max_children等更改流程管理器。我没有抽出时间到5。。。如果你把这个写下来作为回答,我会接受的。我建议为fastcgi_pass也加入正确的规范,因为我显然把它搞砸了。德克萨斯州!检查1-sudo服务php5 fpm状态,2-将套接字更改为tcp/ip时删除unix,即默认->fastcgi_pass 127.0.0.1:9000,www.conf->listen 127.0.0.1:9000;3-尝试增加php的进程管理器,即pm.max_children=40,pm.start_servers=10,pm.min_spare_servers=5,pm.max_spare_servers=10 4-从nginx.conf 5关闭keepalive连接-尽可能尝试实现缓存。有效的方法是按照您指定的pm.max_children等更改流程管理器。我没有抽出时间到5。。。如果你把这个写下来作为回答,我会接受的。我建议为fastcgi_pass也加入正确的规范,因为我显然把它搞砸了。德克萨斯州!
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].
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3