网站建设相关知识
网友的站点使用Nginx/Tengine的时候部分页面出现了504 gateway time-out错误。他用的阿里云轻量应用服务器,Centos7.4,Tengine(Nginx)+php5.6。
出现这个提示,按照字面上的意思就是504网关超时。一般是网站程序对提交的请求响应超时,超过了设置的最大等待时间。
这位网友出现这种情况是因为后台请求的内容列表过多,数据有两万多条。这种情况下,我们优先考虑优化程序,减少程序的执行时间。如果不能优化程序或者优化程序效果不好,我们可以通过修改配置增大超时时间。
1、修改Nginx配置。
在nginx.conf中的http层加上fastcgi参数如下:
1 2 3 4 5 6 7 | 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参数并修改。
1 2 3 4 |
在php-fpm.conf中找到request_terminate_timeout 参数并修改
1 2 3 4 5 6 7 | ; 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或重载配置。
上一篇:网站首页内容页长尾关键词布局?
下一篇:网站搭建使用云存储的好处