Hello everyone,
after the great help from you, I finishid building my simple web chat app using Django channels.
Now I wanted to move to a production state. I have already set up the communication between Django and Nginx with uWSGI. I got a SSL certificate installed by certbot.
When testing my chat app I got this error in the browser:
NS_ERROR_WEBSOCKET_CONNECTION_REFUSED
from line 4 in my websocket.js file, which reads
const webSocket = new WebSocket(
'wss://' + window.location.host + '/ws/chat/'
);
This is my nginx configuration file:
# The upstream component nginx needs to connect to
upstream django {
server unix:///home/production/myproject/myproject.sock;
}
# Configuration of the server
server {
server_name myproject.com;
charset utf-8;
# max upload size
client_max_body_size 75M;
# Django media and static files
location /media {
alias /home/production/myproject/media;
}
location /static {
alias /home/production/myproject/static;
}
# Send all non-media requests to the Django server
location / {
uwsgi_pass django;
include /home/production/myproject/uwsgi_params;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/myproject.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/myproject.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = myproject.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name myproject.com;
return 404; # managed by Certbot
}
I have already tried adding this, which I found after some research, or some other form of this to the configuration but that didn’t help.
# WebSocket handling
location /ws/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_redirect off;
proxy_pass http://127.0.0.1:8001/ws/;
}
How do I get this to work? I am happy to give more information if needed.
Thanks in advance