Websocket error when using Elastic Beanstalk with Django channels

I am trying to get a chat application running on django channels to work with AWS Elastic Beanstalk with a load balancer.

I basically modify the code from https://github.com/jacobian/channels-example to work with an elastic bean stack. I can successfully run it locally with the command

python manage.py runserver 

The problem is when I deploy it using Elastic Beanstalk, I get the following error when launching the chat application.

 WebSocket connection to 'wss://mydomain.com/test/' failed: Error during WebSocket handshake: Unexpected response code: 200 

I have tried the solutions suggested in https://stackoverflow.com/a/3/4129/129 , but it just showed a different error code

 WebSocket connection to 'wss://mydomain.com/test/websocket' failed: Error during WebSocket handshake: Unexpected response code: 404 

I also already changed the load balancer listener port to TCP 80 and received an SSL certificate to change the safe listener port to SSL 443, but still get the same error.

I also read Websockets from socket.io on AWS Elastic Beanstalk , but there is no way to configure a proxy server for Django, I think it uses Apache by default.

What am I missing for setting up Elastic Beanstalk to make it work?

Is there a way to change this so that we can start the daphne server with asgi?

+7
django elastic-beanstalk websocket redis django-channels
source share
1 answer

I'm not on Elastic Beanstalk, but here is my configuration for VPS. Ubuntu 14.04 with nginx and a supervisor. The task of the supervisor is to ensure that the server and workflow are always up and running. Nginx listens on port 8000 on the local host and forwards it to 8080 and 443.

 # nginx.conf server { listen 8080 default_server; server_name example.com; return 301 https://example.com$request_uri; } server { listen 443 default_server ssl; server_name example.com; # ... SSL stuff # Send root to the ASGI server location / { proxy_pass http://localhost:8000; proxy_http_version 1.1; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; } # Static Files location /static/ { root /home/ubuntu/project; } # Media Files location /media/ { root /home/ubuntu/project; } } 

This is what my supervisor configuration looks like. I start the server just by restarting the sudo service supervisor restart

 # supervisord.conf [program:project_server] directory=/home/ubuntu/project/ command=/home/ubuntu/project/venv/bin/daphne project.asgi:channel_layer --port 8000 --bind 0.0.0.0 [program:project_worker] process_name=project_worker%(process_num)s numprocs=3 directory=/home/ubuntu/project/ command=/home/ubuntu/project/venv/bin/python /home/ubuntu/project/manage.py runworker [group:project] programs=project_server,project_worker 
0
source share

All Articles