J
J
John2016-11-30 13:01:40
Django
John, 2016-11-30 13:01:40

How to make Nginx see Websocket?

There is an Ubuntu 16 server on which Django hangs along with the Django Channels module (web sockets). Installed gunicorn and nginx. I did everything except websocket. Errors 404, 502, Error in connection establishment: net::ERR_CONNECTION_REFUSED when connecting
Here is nginx.conf:

http {
        map $http_upgrade $connection_upgrade {
                default upgrade;
                ''      close;
        }

        server {
                listen 3000;

                root /home/azureuser/myapp/;

                location = /favicon.ico { access_log off; log_not_found off; }

                location /static/ {
                        autoindex on;
                }

                location / {
                        include proxy_params;
                        proxy_pass http://unix:/home/azureuser/myapp/myapp.sock;
                }

                location /api/chat/connect {
                        proxy_pass http://localhost:8000/;
                        proxy_http_version 1.1;
                        proxy_set_header Upgrade $http_upgrade;
                        proxy_set_header Connection $connection_upgrade;
                }
        }

Tried different articles:
nginx.org/ru/docs/http/websocket.html
https://habrahabr.ru/post/171757/
And + about 8 more articles. I inserted each directly, corrected my own. Basically a connection failure error. The server hangs on ms azure.
Ports open: 8000, 8080, 80, 3000
------
I tried proxying two .socks, one myapp.sock second ws.sock, doesn't help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bobsans, 2016-12-09
@Bobsans

There was a similar problem recently. The solution was not obvious. I connected a dedicated IP to the VPS and everything worked.
See if the server sends the Upgrade: WebSocket and Connection: Upgrade headers in the response to the socket connection.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question