nginx代理WebSocket无法访问ws//WebSocket/xxxx

NGINX通过允许一个在客户端和后端服务器之间建立的隧道来支持WebSocket。为了NGINX发送来至于客户端Upgrade请求到后端服务器,Upgrade和Connection头部必须被设置明确。
示例,这里我们使用nginx来做代理。

upstream wsbackend {
        server 127.0.0.1:3000;
    }

    server {
        listen       8090;
        server_name  localhost;

        #charset koi8-r;

        #access_log logs/host.access.log main;

        # location / {
        # root html;
        # index index.html index.htm;
        # }

        location / {
            proxy_pass http://wsbackend;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }
    }