Nginx configuration for the Tornado websocket demo

2019-02-15 15:27发布

Can someone please provide me with Nginx configuration for the Tornado websocket chat demo? the demo is located under /tornado/demos/websocket...

1条回答
爷、活的狠高调
2楼-- · 2019-02-15 15:38

A config like this will work:

events {
    worker_connections  1024;
}

http {
    upstream chatserver {
        server 127.0.0.1:8888;
    }

    server {
        # Requires root access.
        listen       80;

        # WebSocket.
        location /chatsocket {
            proxy_pass http://chatserver;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
        }

        location / {
            proxy_pass http://chatserver;
        }
    }
}

You'll need to run Nginx as root in order to listen on port 80. Now you can visit "localhost" with your browser. More info on Nginx and websockets here.

查看更多
登录 后发表回答