Django Daphne Websocket Access Denied

0

We need to establish a "Web socket connection" to our AWS servers using Django, Django channels, Redis, and Daphne Nginx Config. Currently local and on-premises config is configured properly and needs help in configuring the same communication with the staging server.

We tried adding the above config to our servers but got an error of access denied with response code 403 from the server for web socket request.

below is the Nginx config for staging

server {
    listen 80;
    server_name domain_name.com domain_name_2.com;
    root /var/www/services/project_name_frontend/;
    index index.html;

    location ~ ^/api/ {
        rewrite ^/api/(.*) /$1 break; 
        proxy_pass http://unix:/var/www/services/enerlly_backend/backend/backend.sock;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header Host $host; 
        proxy_read_timeout 30;
        proxy_connect_timeout 30;
        proxy_send_timeout 30;
        send_timeout 30;
        proxy_redirect ~^/(.*) $scheme://$host/api/$1; 
    }

    location /ws {
        try_files $uri @proxy_to_ws;
    }

    location @proxy_to_ws {
        proxy_pass  http://127.0.0.1:8001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_redirect off;
    }

    location ~ ^/admin/ {
        proxy_pass http://unix:/var/www/services/project_name_backend/backend/backend.sock;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 
        proxy_set_header Host $host;  
        proxy_read_timeout 30;
        proxy_connect_timeout 30;
        proxy_send_timeout 30;
        send_timeout 30;
        proxy_redirect off;
    }

    location /staticfiles/ {
        alias /var/www/services/project_name_backend/backend/staticfiles/;
    }

    location /mediafiles/ {
        alias /var/www/services/project_name_backend/backend/mediafiles/;
    }
    location / {
        try_files $uri /index.html;  
    }

}

and Systemctl service to execute Django Daphne service

[Unit]
Description=Backend Project Django WebSocket daemon
After=network.target

[Service]
User=root
Group=www-data
WorkingDirectory=/var/www/services/project_name_backend
ExecStart=/home/ubuntu/project_python_venv/bin/python /home/ubuntu/project_python_venv/bin/daphne -b 0.0.0.0 -p 8001 project_name_backend.prod_asgi:application

[Install]
WantedBy=multi-user.target

Below is the Load Balancer security group config inbound rules Enter image description here

Listner Config for Load Balancer Enter image description here

Enter image description here

没有答案

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则