I created a django-channels app that works without any problem in local. I’m now trying to deploy it to a DigitalOcean droplet. The whole Django WSGI part works, the only part not working is Django-Channels. If i try to connect to any consumer like below:

ws://MYURL:9000/main

I get the following error on my Chrome console:

WebSocket connection to 'ws://MYURL:9000/main' failed: Error in connection establishment: net::ERR_CONNECTION_TIMED_OUT

Daphne service:

[Unit]
Description=Daphne service
After=network.target


[Service]
PIDFile=/run/daphne/pid
User=root
Group=root
WorkingDirectory=/django-vue-mpa
ExecStart=/django-vue-mpa/venv/bin/daphne --bind 0.0.0.0 --port 9000 --verbosity 0 django_vue_mpa.asgi:application
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
Restart=on-abort
PrivateTmp=true


[Install]
WantedBy=multi-user.target

And here is my actual nginx conf:

server {
    listen 80;
    server_name http://MYURL/;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /django-vue-mpa/django_vue_mpa;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/django-vue-mpa/django-vue-mpa.sock;
    }
}

What am i doing wront here? The exact same code works locally, but it looks like whenever i try to access django channels from outside i get refused.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hi @hst02,

This usually is something simple. I’ll recommend checking if the port you are using 9000 is actually allowed to the public.

The error you’ve provided often indicates exactly that.

Submit an Answer