如何在nginx服务器中打开ws协议?

时间:2014-06-06 14:33:47

标签: nginx websocket

我在socket.ibrahimyilmaz.me上运行了简单的聊天服务器(我改变了龙卷风websocket示例)并且在我的本地我可以到达我的服务器ws://127.0.0.1:8888但是在生产环境中,我只能到达http但我希望能够在nginx服务器上使用ws协议。

1 个答案:

答案 0 :(得分:1)

http {
    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }

    server {
        # the usual stuff...

        location /chat/ {
            proxy_pass http://backend;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
        }
    }

来源:http://nginx.org/en/docs/http/websocket.html

相关问题