Configuration to configure nginx with django and nodejs for websocket (wss: //)

I have the following configuration to install a django application for service via uwsgi on nginx

upstream node{
    server 127.0.0.1:8081  max_fails=1 fail_timeout=20s;

}
server {
    listen 8000 default_server ssl;
    server_name bla.bla;

    ssl_certificate path;
    ssl_certificate_key path;

    location /serve {
        proxy_pass http://node;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_cache_bypass 1;
        proxy_no_cache 1;
        proxy_redirect off;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_connect_timeout 2s;
    }
    location / {
        include         uwsgi_params;
        uwsgi_pass      unix:///var/uwsgi/sel.sock;
    }
}

I have a nodejs server with a websocket server running on port 8081

var WebSocketServer = require('ws').Server
  , wss = new WebSocketServer({ port: 8081, path: "/serve" });

Now when I access the websocket server in my html page using

var websocket = new WebSocket("wss://host:8081/serve"); // works
var websocket = new WebSocket("wss://host:8000/serve"); // doesn't work get 504 error

What am I doing wrong? Can someone point out my error and show a pointer to its correct setting.

EDIT: my nginx version is nginx version: nginx / 1.4.6 (Ubuntu)

+4
source share
1 answer

wss WebSocket TLS. wss://host:8081 , node.js . nginx TLS .

0

Source: https://habr.com/ru/post/1651087/


All Articles