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

답변 없음

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠