51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

nginx 配置 websocket

websocket 长链接 配置

解决nginx转发websocket报400错误

解决nginx转发websocket报400错误_error: unexpected server response: 400-CSDN博客

其中最重要的是下面这三行

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
其中第一行是告诉nginx使用HTTP/1.1通信协议,这是websoket必须要使用的协议。

第二行和第三行告诉nginx,当它想要使用WebSocket时,响应http升级请求。

server {
	listen 8191;
	server_name uat-baimeidashu.com;
        location / {
            proxy_pass http://192.168.1.209:31805;
            include proxy_params;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
          }        
}

赞(3)
未经允许不得转载:工具盒子 » nginx 配置 websocket