如何设置我的nginx配置文件以允许通过Tornado连接websocket



我在使用nginx作为反向代理向Tornado提供websocket连接时遇到问题。没有nginx(直接馈送到Tornado),websocket连接可以正常工作,而最新版本的nginx应该支持websocket,所以我的配置文件中一定有错误。。。错误(来自最新的出血边缘Chrome测试版)是:

Error during WebSocket handshake: 'Connection' header value is not 'Upgrade'

以下是我的nginx.conf文件中的相关部分:

location / {
    proxy_pass_header Server;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Scheme $scheme;
    proxy_pass http://tornadoes;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}

显然你需要在Ubuntu上强制升级nginx:

sudo apt-get install python-software-properties
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get upgrade nginx
service nginx status

最新更新