系统在做service mesh改造的时候,前端http请求调用后端微服务,走代理网关。
发现接口请求的时候状态码是426 Upgrade Required,需要升级http协议版本
原因
nginx 默认的http协议版本是1.0,需要升级到1.1
前端项目容器的基本镜像版本是 nginx:1.17.3
加挂的容器数据卷,nginx.conf 配置文件:
解决
增加配置:
proxy_http_version 1.1;
# https://www.nginx.org.cn/question/detail/95upstream upserver {server 127.0.0.1:12349;### keepalive 100;}server {listen 12347;location /hello {proxy_pass http://upserver;proxy_http_version 1.1; # 指定协议版本,默认 1.0proxy_set_header Connection ""; # 设置Connection为长连接(默认为no)}}
即upstream关闭 keepalive,但是server里明确指定 HTTP 1.1协议
通过tcpdump抓包可以看到nginx端使用HTTP 1.1协议请求upstream server,请求完毕之后发送FIN包关闭连接了!!!
