[Fixed]-Django channels behind https

15๐Ÿ‘

I would suggest changing your things as follow.

javascript:

var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws";
var chatsock = new ReconnectingWebSocket(ws_scheme + '://' + window.location.host + window.location.pathname);

nginx:

server {
 listen 443 ssl;
 server_name server.domain.com;

 ssl on;
 ssl_certificate /path_to_server_certificate.crt;
 ssl_certificate_key /path_to_server_key.key;

  ## static files (path should be changed)
  location /static/ {
    autoindex off;
    alias /blabla/static/;
  }

  ## app
  location / {
    proxy_pass http://127.0.0.1:8000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
  }

}
๐Ÿ‘คItamar Lavender

Leave a comment