使用了Nginx的反向代理配置如下:
upstream test{
keepalive 1;
server 192.168.1.63:4000;
}
server {
listen 4000;
server_name localhost;
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_buffering off;
proxy_pass http://test;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
無法與后端服務保持長連接,即時后端服務顯示返回Connection:keep-alive給nginx。
抓包發現:nginx默認使用了http1.0協議向后端轉發請求,頭中顯示指定了Connection: close ,修改配置如下:
proxy_http_version 1.1;
proxy_set_header Connection "";
長連接生效。
PS:新版的wireshark “不能”失敗HTTP1.0