############ 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>
Powered by ddoss.cn 12.0
©2015 - 2025 ddoss
渝公网安备50011302222260号
渝ICP备2024035333号
【实验平台安全承诺书】
小绿叶技术社区,优化网络中,点击查看配置信息
主机监控系统: 安全防火墙已开启检查cc攻击-下载文件完成后等待10s 恢复访问,检查连接数低于峰值恢复访问
您的IP:216.73.216.110,2025-12-01 18:35:13,Processed in 0.0218 second(s).