使用tornado + nginx + WebSocket 时出现 400 错误代码的解决方法
错误提示
1
WebSocket handshake: Unexpected response code: 400 nginx
解决方法
修改nginx 配置文件,如下例子
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
server {
listen 80;
root /home/chl/chat;
index index.html index.htm;
server_name _;
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
}
其中下面三行是重要的
1
2
3
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
官方的配置 http://nginx.org/en/docs/http/websocket.html
本文网址: https://pylist.com/topic/132.html 转摘请注明来源