记一次 An error occurred.(504 Gateway Time-out)错误处理过程

来源:互联网 发布:手机软件加密 软件 编辑:程序博客网 时间:2024/05/14 06:08

一、发现问题

网站正常访问,但是其中一个连接点击等1分钟后直接出一下错误:

 

Anerror occurred.

 

Sorry,the page you are looking for is currently unavailable.

Pleasetry again later.

 

Ifyou are the system administrator of this resource then you should check theerror log for details.

 

Faithfullyyours, nginx.

 

 

二、问题分析过程

1、首先考虑后台是否报错了,通过监控TOMCAT日志发现没有任何异常,可排除程序本身的问题

2、看页面错误发现有说nginx,结合项目该请求后台会进行多个大SQL查询,相应时间较长,考虑相应超时,查看nginx.conf配置文件查找关于设置时间相关的,只发现设有一个keepalive_timeout 65;,直接将其扩大十倍,重启nginx查看效果,发现异常未解决

3、百度搜索an erroroccurred. nginx相关问题,发现各种解决方式如

http://blog.csdn.net/achilles12345/article/details/49055953

......

http://blog.csdn.net/u011650048/article/details/51729616

......等等,各种修改近似

fastcgi_connect_timeout 300;

fastcgi_send_timeout 300;

fastcgi_read_timeout 300;

fastcgi_buffer_size 64k;

fastcgi_buffers 4 64k;

相关参数的信息及其他关于过期时间的修改等,多次重启后发现问题依然存在。

4、继续查看相关问题,考虑延迟问题,通过F12查看请求的网络相应过程,发现控制台抛出

Failed to load resource: the server respondedwith a status of 504 (Gateway Time-out)

相继搜索关于504 (Gateway Time-out)的各种解决方式,如:

http://www.cnblogs.com/xiaozong/p/5071259.html

......

http://jingyan.baidu.com/article/6fb756ecbf4774241858fb9a.html

......

等等,各种关于nginx修改与3有雷同及相同之处,发现问题问题依然未能解决

5、由此考虑是否是tomcat链接数不够用,或者是相应时间过短等问题造成了nginx自动断了响应等,百度搜索tomcat链接超时问题,获取量修改如:

http://blog.csdn.net/liufuwu1/article/details/54890834

对于connectionTimeout链接时间以及关于修改最大并发请求连接数,需要修改maxThreads和acceptCount两个参数,但是修改重启tomcat后发现相关问题依然未解决

 

三、解决问题

上边各种修改试了没招了,查看nginx错误日志,发现没有记录关于504的相关错误,于是

1、修改nginx.conf的顶上#error_log  logs/error.log  info;,将注释放开重启nginx,然后通过tail -ferror.log 命令关注nginx日志信息,然后让问题重现

2、发现nginx抓取到了异常:

2017/05/31 19:03:13 [error] 22358#0: *1upstream timed out (110: Connection timed out) while reading response headerfrom upstream, client: 223.223.204.244, server: localhost, request: "GET/platform/totalData HTTP/1.1", upstream:"http://10.163.171.188:94/platform/totalData", host:"rep.jinrongboshi.com", referrer: "http://rep.jinrongboshi.com/page/left.jsp"

3、由此根据 upstream timedout (110: Connection timed out) 进行搜索,获取

http://www.ttlsa.com/nginx/nginx-upstream-timed-out-110-connection-timed-out/

根据其提示调整

location / {

       ...

       proxy_read_timeout 150; #重点

       ...

    }

在nginx.conf的location中添加proxy_read_timeout 150;

重启nginx

发现问题OK了。

原创粉丝点击