HttpClient
客户端访问服务器,产生的超时现象
client HttpClient(connectionTimeout, socketTimeout) -> server
若socketTimeout<server响应时间,则报异常Read timed out(java.lang.Exception: Read timed out);
conectionTimeout:连接建立的时间(tcp三次握手时间);
socketTimeout:等待数据的时间或者两个包之间的间隔时间;
解决方案:
这个很简单,只需要增加到连接时间和数据读取时间即可。
post(String url, String body, String mimeType, String charset, Integer connTimeout, Integer readTimeout)
Nginx
一般这种后端为tomcat,nginx代理报504超时错误。
解决方案如下:
全局修改:
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
#用于tomcat反向代理,解决nginx 504错误
proxy_connect_timeout 300; #单位秒
proxy_send_timeout 300; #单位秒
proxy_read_timeout 300; #单位秒
proxy_buffer_size 16k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 128k;
proxy_temp_file_write_size 128k;
# ps:以timeout结尾配置项时间要配置大点
}
只对 修改server{}
location / {标签:http,log,300,nginx,proxy,timeout,504,gateway From: https://blog.51cto.com/u_15461374/5938146
proxy_pass http://182.61.131.62:33060/;
proxy_redirect off;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}