码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx 502 Bad Gateway 解决方法

时间:2014-10-18 00:39:47      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:http   io   os   ar   使用   for   strong   sp   文件   

1查看fastcGI进程 ps -ef|grep ‘php-fpm‘ 若没启动,启动

2系统文件打开数 

ulimit -n 4096
查看所有进程的文件打开数
lsof |wc -l
查看某个进程打开的文件数
lsof -p pid |wc -l

一、fastcgi缓冲区设置过小 

  http {
    ...
    fastcgi_buffers 8 16k;
    fastcgi_buffer_size 32k;
    ...
  }

二、代理缓冲区设置过小
如果你使用的是nginx反向代理,如果header过大,超出了默认的1k,就会引发上述的upstream sent too big header (说白了就是nginx把外部请求给后端处理,后端返回的header太大,nginx处理不过来就会导致502。

server {
listen 80;
server_name *.lxy.me;

location / {

###############
proxy_buffer_size 64k;
proxy_buffers 32 32k;
proxy_busy_buffers_size 128k;
###############
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
............
}

三、默认php-cgi的进程数设置过少
在安装好使用过程中出现502问题,一般是因为默认php-cgi进程是5个,可能因为phpcgi进程不够用而造成502,需要修改/usr/local/php/etc/php-fpm.conf 将其中的max_children值适当增加。也有可能是max_requests值不够用。需要说明的是这连个配置项占用内存很大,请根据服务器配置进行设置。否则可能起到反效果。

四、php执行超时
php执行超时,修改/usr/local/php/etc/php.ini 将max_execution_time 改为300

五、nginx等待时间超时
部分PHP程序的执行时间超过了Nginx的等待时间,可以适当增加nginx.conf配置文件中FastCGI的timeout时间

http {
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
......
}

Nginx 502 Bad Gateway 解决方法

标签:http   io   os   ar   使用   for   strong   sp   文件   

原文地址:http://www.cnblogs.com/jking10/p/4032334.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!