解决Nginx 504 Gateway Time-out 和502 Bad Gateway错误:
尝试解放方案一:(经过测试此方案未解决问题)
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
http { include mime.types; include extra/*.conf; default_type application/octet-stream; sendfile on; keepalive_timeout 65; fastcgi_connect_timeout 60; fastcgi_send_timeout 180; fastcgi_read_timeout 180; fastcgi_buffers 4 256k; fastcgi_buffer_size 128k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors on; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 9; gzip_types text/plain application/javascript text/css application/xml; gzip_vary on; } |
方案二:
0 1 2 3 4 5 6 7 8 9 10 |
[root@hz log]# vim /usr/local/php/etc/php-fpm.conf ################################################## pm = static 或者 pm = dynamic pm.max_children = 10 #当设置pm = static时候生效,开启10个进程 pm.start_servers = 4 #当设置pm = dynamic时候生效,默认启动4个进程 pm.min_spare_servers = 4 #当设置pm = dynamic时候生效,最小启动4个进程 pm.max_spare_servers = 12 #当设置pm = dynamic时候生效,最大启动4个进程 slowlog = log/$pool.log.slow #开启慢日志查询功能 request_slowlog_timeout = 15 #当超过60s的时候会被记录到/usr/local/php/log request_terminate_timeout = 120 #设置单个请求的超时中止时间 ################################################## |
优化方案三:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
[root@LNMP extra]# cat ../php-fpm.conf [global] [www] user = www group = www listen = 127.0.0.1:9000 ;listen = /tmp/php.sock pm = static pm.max_children = 12 pm.start_servers = 4 pm.min_spare_servers = 4 pm.max_spare_servers = 10 slowlog = log/$pool.log.slow request_slowlog_timeout = 10 request_terminate_timeout = 40 include = etc/extra/*.ini ################解决一个网站卡死所有网站都无法访问的问题################ [root@LNMP extra]# cat web.ini [web] user = www group = www listen = 127.0.0.1:9010 pm = dynamic pm.max_children = 10 pm.start_servers = 5 pm.min_spare_servers = 3 pm.max_spare_servers = 8 |
备注:一些程序引起的504错误,可以参考方案二的设置,因为有一些程序会调用非常多的php进程,因此请根据实际情况进行调整,一般情况下children的设置以内存大小为准则(我测试的一个php-fpm进程占用实际内存为24M-28M左右),同时请注意如果开启非常多的php-fpm进程,会占用非常多的CPU资源,SO请进行综合考虑,进行最优化配置!SourceByrd's Weblog-https://note.t4x.org/system/nginx-gateway-time-out/
申明:本文由BYRD原创(基于PHP5.5.11的压力测试得出的数据),未经许可禁止转载!SourceByrd's Weblog-https://note.t4x.org/system/nginx-gateway-time-out/ SourceByrd's Weblog-https://note.t4x.org/system/nginx-gateway-time-out/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!