[Answered ]-Proxy redirecting websockets and http to the same (unix) socket

2๐Ÿ‘

โœ…

I found a solution :

I instanciate my websockets like this :

var socket = new WebSocket(ws_scheme + "://" + window.location.host
                           + "/ws" + window.location.pathname);

So I can just separate request coming to /ws and requests coming to /.

So I just did this :

upstream django_ws {
         server unix:///path/to/ws.sock;
}

server {
       listen 8082;
       server_name 127.0.0.1;
       charset utf-8;

       root /path/to/root;

       set $myroot $document_root;


       location /ws {
                proxy_pass http://django_ws;
                proxy_http_version 1.1;
                proxy_set_header Upgrade websocket;
                proxy_set_header Connection upgrade;
       }

       location / {
                proxy_pass http://django_ws;
       }
}

and it worked just fine!

๐Ÿ‘คvmonteco

Leave a comment