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 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(适当增加时长);

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

罗小爬EX

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值