Search code examples
nginxwebsockettornado

How do I setup my nginx configuration file to allow websocket connections via Tornado?


I'm experiencing issues using nginx as a reverse-proxy to feed websocket connections to Tornado. The websocket connections work fine without nginx (feeding directly to Tornado), and the latest version of nginx is supposed to support websockets, so there must be a mistake in my configuration file... The error (from the latest bleeding edge Chrome beta) is:

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

Here are the relevant bits from my nginx.conf file:

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

Solution

  • Apparently you need to force upgrade nginx on Ubuntu:

    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