1000字范文,内容丰富有趣,学习的好帮手!
1000字范文 > 504 gateway timeout解决方法

504 gateway timeout解决方法

时间:2024-05-29 20:28:47

相关推荐

504 gateway timeout解决方法

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 thisConnectorwill 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). UnlessdisableUploadTimeoutis set tofalse, 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 thisConnectorwill wait for another HTTP request before closing the connection. The default value is to use the value that has been set for theconnectionTimeoutattribute. Use a value of -1 to indicate no (i.e. infinite) timeout.

Tomcat配置参见:/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配置参见:/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(适当增加时长);

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。