504 gateway timeout解决方法
1.HttpClientclient HttpClient(connectionTimeout, socketTimeout) -> server若socketTimeout<server响应时间,则报异常Read timed out(java.lang.Exception: Read timed out);conectionTimeout:连接建立的时间(tcp三次握手时...
1.HttpClient
client HttpClient(connectionTimeout, socketTimeout) -> server
若socketTimeout<server响应时间,则报异常Read timed out(java.lang.Exception: Read timed out);
conectionTimeout:连接建立的时间(tcp三次握手时间);
socketTimeout:等待数据的时间或者两个包之间的间隔时间;
2.Tomcat
connectionTimeout:client连接成功后,Tomcat Connector等待request URI行的时间(默认60s)
The number of milliseconds this Connector will wait, after accepting a connection, for the request URI line to be presented. Use a value of -1 to indicate no (i.e. infinite) timeout. The default value is 60000 (i.e. 60 seconds) but note that the standard server.xml that ships with Tomcat sets this to 20000 (i.e. 20 seconds). Unless disableUploadTimeout is set to
false
, this timeout will also be used when reading the request body (if any).
keepaliveTimeout:针对Http connection keepalive机制(浏览器端同一个connection可以发送多次请求,即连接重用),若在此时间间隔内没有接到请求,则关闭连接(默认同connectionTimeout,60s),该属性可结合maxKeepAliveRequests(一个连接最多可以发送的pipeline请求数)一起使用;
The number of milliseconds this Connector will wait for another HTTP request before closing the connection. The default value is to use the value that has been set for the connectionTimeout attribute. Use a value of -1 to indicate no (i.e. infinite) timeout.
Tomcat配置参见:https://tomcat.apache.org/tomcat-8.5-doc/config/http.html
3.Nginx
关于nginx中几个导致504 Gateway Timeout核心配置如下:
proxy_connect_timeout: 建立连接的超时时间(默认60s);
proxy_send_timeout:nginx发送给proxied Server请求的超时时间(默认60s);
proxy_read_timeout:nginx接收proxied Sever响应的超时时间(默认60s);
nginx配置参见:https://nginx.org/en/docs/http/ngx_http_proxy_module.html
总结
在browser->app1->app2(处理时间>60s)的调用过程中:
(1)前端browser看见504的错误: 设置app1的Nginx proxy timeout(默认60s,适当增加时长);
(2)app1调用app2时,在app1中看见调用app2时报504的错误: 设置app2的Nginx proxy timeout(默认60s,适当增加时长);
(3)app1调用app2时,在app1中看见调用app2时报readtimeout的错误: 设置app1的HttpClient socketTimeout(适当增加时长);
更多推荐
所有评论(0)