2

I'm hosting a Python WebSocket server written in Tornado. For that purpose I've written an nginx config, but it doesn't seem to work.
The exact issue is that when I try to establish a connection from a WS client, it fails and the following record appears in the server logs:

WARNING:tornado.access:400 GET / (127.0.0.1) 2.07ms

My application is set up so that only WebSockets will be served on root (/), but judging by the logs, it seems that my request somehow gets transformed to HTTP, therefore my server blocks the connection.

This is my nginx configuration file:

server {
    listen 80;

    # host name to respond to
    server_name ws.example.com;

    location / {
        # switch off logging
        access_log off;

        # redirect all HTTP traffic to localhost:8080
        proxy_pass http://localhost:8080;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # WebSocket support (nginx 1.4)
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
}

A config from this question didn't work - the issue was the same.
This question looks similar, but its answer also didn't help.
Any ideas?

Community
  • 1
  • 1
illright
  • 3,991
  • 2
  • 29
  • 54

0 Answers0