收藏文章 楼主

Nginx apache 502 解决方案

版块:linux   类型:普通   作者:小绿叶技术博客   查看:517   回复:0   获赞:3   时间:2020-09-09 23:32:22

############ Nginx 502  ############

1.首先,把后端代码恢复到上一次没报错之前的版本,因为nginx报错不一定绝对是nginx的问题,先把系统恢复成可以运行的状态,这是控制变量法呀。


2.重新加载nginx的配置文件


nginx -c /usr/local/webserver/nginx/conf/nginx.conf

如果你不能全局运行nginx命令,请加上nginx的路径。-c后面的参数为nginx配置文件所在路径这是要求nginx重新添加配置文件地址。


nginx -s reload

重新加载文件


3.重新运行,可以看到会出现如下错误:


nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

nginx: [emerg] still could not bind()

可以看到,是进程端口被占用了,可以看系统是否已有nginx在运行。


运行命令:ps -aux | grep nginx




然后对照,发现第一个和第二个的pid分别为130616,130635,kill掉即可。


kill 130616

kill 130635


kill -9


排查方法2.

通常的排查方法如下:

1、查看php fastcgi的进程数(max_children值)

# netstat -anop | grep php-cgi | wc -l

# netstat -anpo | grep php-fpm | wc -l

假如显示是5

2、查看当前进程

# ps aux | grep php-fpm 观察fastcgi/php-fpm进程数,假如使用的进程数等于或高于5个,说明需要增加。

3、调整/usr/local/php/etc/php-fpm.conf 的相关设置

pm.max_children = 5

request_terminate_timeout = 60

max_children最多5个进程,按照每个进程20MB内存,最多100MB。也就是1分钟。max_children增多,则php-cgi的进程多了就会处理的很快,排队的请求就会很少。

但是设置max_children也需要根据服务器的性能进行设定,一般来说一台服务器正常情况下每一个php-cgi所耗费的内存在20M左右。根据自己服务器购买的内存来实际决定。

request_terminate_timeout执行的时间为60秒,request_terminate_timeout值可以根据服务器的性能进行设定。一般来说性能越好你可以设置越高,20分钟-30分钟都可以。

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

http

{

......

fastcgi_connect_timeout 300;

fastcgi_send_timeout 300;

fastcgi_read_timeout 300;

......}





##########  apache 502  #########

<VirtualHost *:80>

    ServerName www.xxx.com

ProxyRequests Off

        

ProxyPreserveHost On

ProxyPass / http://127.0.0.1:8888/ Keepalive=On

ProxyPassReverse / http://127.0.0.1:8888/

    ErrorLog "logs/www.xxx.com_error.log"

    CustomLog "logs/www.xxx.com_access.log" common

</VirtualHost>

提供企业建站服务,免费网防系统,提交信息登录 http://yundun.ddoss.cn 邮箱: proposal@ddoss.cn 
回复列表
默认   热门   正序   倒序

回复:Nginx apache 502 解决方案

头像

用户名:

粉丝数:

签名:

资料 关注 好友 消息