Django.fun

Not able to connect with server websocket it showing me status -502 Bad Gateway in django

I have configure Django Channels successfully in my local it is working fine in my local, also I'm able to chat one to one using websocket. when I try to deploy it to server and try to connect with websocket it shows status 502 Bad Gateway. I try so many thing but i'm stucked now anyone of you guys can help me to overcome this problem thanx in advance.

This is the nginx configuration of my project..

upstream websocket {
        server www.domain_name.com:8000;
        #SERVER endpoint that handle ws:// connections
    }

server {
    server_name www.domain_name.com;
    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /root/django/app;
    }
    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
        proxy_headers_hash_max_size 512;
        proxy_headers_hash_bucket_size 128;
   }
    location /v1 {
        include proxy_params;
        client_max_body_size 100M;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_http_version 1.1;
        proxy_pass http://websocket;
}
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/www.domain_name.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.domain_name.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
    if ($host = www.domain_name.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot
    listen 80;
    server_name www.domain_name.com;
    return 404; # managed by Certbot
}

The error I got in nginx errors.log in below screenshot. enter image description here

Tutorials

Современный Python: начинаем проект с pyenv и poetry

Настройка проекта Python — виртуальные среды и управление пакетами

Использование requests в Python — тайм-ауты, повторы, хуки

Понимание декораторов в Python

ProcessPoolExecutor в Python: полное руководство

map() против submit() с ProcessPoolExecutor в Python

Понимание атрибутов, словарей и слотов в Python

Полное руководство по slice в Python

Выпуск Django 4.0

Безопасное развертывание приложения Django с помощью Gunicorn, Nginx и HTTPS

Автоматический повтор невыполненных задач Celery

Django REST Framework и Elasticsearch

Докеризация Django с помощью Postgres, Gunicorn и Nginx

Асинхронные задачи с Django и Celery

Релизы безопасности Django: 3.2.4, 3.1.12 и 2.2.24

Выпуски исправлений ошибок Django: 3.2.3, 3.1.11 и 2.2.23

Эффективное использование сериализаторов Django REST Framework

Выпуски безопасности Django: 3.2.2, 3.1.10 и 2.2.22

Выпущенные релизы безопасности Django: 3.2.1, 3.1.9 и 2.2.21

Обработка периодических задач в Django с помощью Celery и Docker

View all tutorials →