Nginx/Tengine服务出现504 gateway time-out解决方法

网友的站点使用Nginx/Tengine的时候部分页面出现了504 gateway time-out错误。他用的阿里云轻量应用服务器,Centos7.4,Tengine(Nginx)+php5.6。

Nginx/Tengine服务出现504 gateway time-out解决方法

出现这个提示,按照字面上的意思就是504网关超时。一般是网站程序对提交的请求响应超时,超过了设置的最大等待时间。

这位网友出现这种情况是因为后台请求的内容列表过多,数据有两万多条。这种情况下,我们优先考虑优化程序,减少程序的执行时间。如果不能优化程序或者优化程序效果不好,我们可以通过修改配置增大超时时间。

1、修改Nginx配置。
在nginx.conf中的http层加上fastcgi参数如下:

http {
...
fastcgi_connect_timeout=300; #fastcgi连接超时时间,默认60秒
fastcgi_send_timeout=300; #nginx 进程向 fastcgi 进程发送请求过程的超时时间,默认值60秒
fastcgi_read_timeout =300 #fastcgi 进程向 nginx 进程发送输出过程的超时时间,默认值60秒
....
}

2、修改PHP配置
在php.ini 中找到max_execution_time参数并修改。


; Maximum execution time of each script, in seconds
;
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 1;#限定了脚本的最大执行时间(单位是秒)

在php-fpm.conf中找到request_terminate_timeout 参数并修改

; The timeout for serving a single request after which the worker process will
; be killed. This option should be used when the 'max_execution_time' ini option
; does not stop script execution for some reason. A value of '0' means 'off'.
; Available units: s(econds)(default), m(inutes), h(ours), or d(ays)
; Default Value: 0
;request_terminate_timeout = 0
request_terminate_timeout = 4s;#设置为 ‘0’ 表示 ‘Off’。可用单位:s(秒),m(分),h(小时)或者 d(天)。默认单位:s(秒)。默认值:0(关闭)。

修改配置后注意重启ngnix或重载配置。

业界动态

谷歌Google最新算法更新的关键要点

2018-9-4 9:23:38

业界动态

信息流广告做好这一步,就能轻松提升转化率!

2018-9-4 13:08:41

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索