应用使用nginx代理后端的tomcat应用程序,最近发现有个问题,偶尔请求nginx的时候,会出现502错误,经查,原因为nginx 请求服务端为http1.0 从而使用了短连接,并发的时候导致连接中断,所以修改了nginx 往服务器请求为http 1.1 为长连接,在此记录下,配置文件修改如下:
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#这个加上,才会让java里的代码获取schema的时候,https不会误以为是http
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
文章评论