By Matt Kaye
Hi, I’ve spent quite a bit of time on this problem, and would be incredibly grateful for a solution. I have redis-server running on the server at port 6379, and the Nginx config at sites-available currently looks like this:
server {
server_name mattalexkaye.com www.mattalexkaye.com;
location /static {
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_pass http://127.0.0.1:2901/static;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/home/projects/kaye-tech/socket/kaye_tech.sock;
}
location /wss/ {
proxy_pass http://127.0.0.1:6379;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mattalexkaye.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mattalexkaye.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 = www.mattalexkaye.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = mattalexkaye.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name mattalexkaye.com www.mattalexkaye.com;
listen 80;
return 404; # managed by Certbot
}
Meanwhile, I’ve followed the tutorial on setting up a Django chat room, which works locally, but haven’t been able to get it to work for the server version. My settings.py file looks like this:
ASGI_APPLICATION = "kaye_tech.routing.application"
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": [('localhost', 6379)],
},
},
}
and in the relevant frontend page the Javascript has the following:
var chatSocket = new WebSocket(
"wss://mattalexkaye.com" + "/ws/cards/" + roomName + "/"
);
I’ve quite possibly made some basic mistakes (though it’s not that I haven’t been refreshing Nginx), as I’m new to the whole websocket thing, but any help would be incredible
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
“ws” and “wss” are confused.
var chatSocket = new WebSocket(
"wss://mattalexkaye.com" + "/ws/cards/" + roomName + "/"
);
location /wss/ {
proxy_pass http://127.0.0.1:6379;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
I think location /wss/ is wrong and should be location /ws/.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.