django / channels

Developer-friendly asynchrony for Django

Home Page:https://channels.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

daphne websocket connectio failed

halhwadi opened this issue · comments

  • ubuntu 20.04
  • nginx
  • django channel
  • redis
  • -ssl
  • -daphne

I'm working on deploying my application on ubuntu 20.04, application is working fine on development Env (windows 10 enterprise), however in production websocket connection is failed (whereas http/s is works fine)

I have followed the deployment instructions mentioned on django-channel website but unfortunately not able to get websocket running properly!

These are the 3 errors messages I got it:

The error message I got from daphne is:
connected when load owner is offline False
127.0.0.1:45978 - - [17/Jan/2022:16:28:44] "GET /chat/2/" 200 8834

The error message I got from browser console is:
WebSocket connection to 'wss://bikum.org:80/ws/chat/2_3/' failed:

The error message i got from system log :
Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program down first before starting supervisord.
but when I checked ports using "sudo netstat -peanut" I did not find port 8000 in the list
image

I'm new to nginx and not sure if I missed any configuration, please find nginx configuration file details:

upstream channels-backend {
    server localhost:8000;
}

server {
    listen 80;
    server_name IP_address mydomain;

  location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/husam/myproject;
   }

     location / {
        try_files $uri @proxy_to_app;
    }
    
    location @proxy_to_app {
        proxy_pass http://channels-backend;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Host $server_name;
    }
   
    listen 443 ssl;
    ssl_certificate /etc/letsencrypt/live/mydomain/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/mydomain/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

having the same issue....

Hi @halhwadi

WebSocket connection to 'wss://bikum.org:80/ws/chat/2_3/' failed:

Should't WSS should use port 443?


The error message I got from daphne is:
connected when load owner is offline False
127.0.0.1:45978 - - [17/Jan/2022:16:28:44] "GET /chat/2/" 200 8834

It is a log message, not an error, I think. It says that the request was served properly.

The problem is with the proxy, I guess. Instead of proxying the WSS to WS on the Django/daphne instance, the WSS is proxied as a HTTP request.


The error message i got from system log :
Error: Another program is already listening on a port that one of our HTTP servers is configured to use. Shut this program > down first before starting supervisord.
but when I checked ports using "sudo netstat -peanut" I did not find port 8000 in the list

This is probably an error about the 80 port, not 8000. Probably there is already apache or anginx installed on your server that is blocking you from running nginx.

This isn't really an addressable issue with Daphne I'm afraid. It's the sort of thing sites like Server Fault, or other places specifically about deployment issues, can help you with.