it.openup
it.openup

Reputation: 33

nginx + python + websockets

How can I configure nginx (latest version, they say it supports websockets) to support WebSockets.

And how can I use python to run websockets connection.

That what I want:

Can any body help me?

Upvotes: 2

Views: 6361

Answers (1)

rjacks
rjacks

Reputation: 1033

I took a quick look at the relevant changeset to Nginx, and it looks like all you need to do to start handling websocket requests is to set up a proxy in your nginx config. So for example:

upstream pythonserver {
    server localhost:5000;
}

server {
    // normal server config stuff...

    location /some/uri/here {
        // Minimum required settings to proxy websocket connections
        proxy_pass http://pythonserver;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        // Other settings for this location
    }
}

This little configuration snippet will proxy incoming websocket traffic to your Python application server, assumed in the example to be listening for local connections on port 5000.

Hope this helps.

Upvotes: 3

Related Questions