WebSocket handshake: Unexpected response code: 400 nginx

pylist 295

使用tornado + nginx + WebSocket 时出现 400 错误代码的解决方法:

WebSocket handshake: Unexpected response code: 400 nginx

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;
    }
}

其中这三行是重要的

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

官方的配置 http://nginx.org/en/docs/http/websocket.html 2

登录发表评论

桂公网安备 45122402000014号