Nginx with Django and Gunicorn working with IP but not with domain name

I have been trying to setup my Django backend since 2days but i can't get it to work with my domain name. I have the Next Frontend on Nginx(Port :80) too but it seems to work fine with domain name. But i did the same setup in backend with port 8000 i can't access it using the domain name but works fine with IP. I have tried everything found on the internet but nothing seems to work.

Config for the frontend (Working with domain)

listen 80;
listen [::]:80;
listen 443 ssl;

include snippets/snakeoil.conf;
server_name {domainName};

location = /favicon.ico { access_log off; log_not_found off; }

location / {
            # reverse proxy for next server
            proxy_pass http://localhost:3000;
            proxy_http_version 1.1;
            proxy_headers_hash_max_size 512;
            proxy_headers_hash_bucket_size 128;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;


Config for backend (Not working with domain name)

server {
    listen 8000;
    listen [::]:8000;
    server_name ipaddress;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
            root /root/backend/lithexBackEnd;
    location / {
            include proxy_params;
            proxy_pass http://unix:/run/gunicorn.sock;

Allowed Hosts

ALLOWED_HOSTS = ['localhost','','ip address','*','']

The Gunicorn has been setup and tested and seems to be working fine .

The error log of Nginx gives the following error when i try to access the port via the domain name.


2023/01/22 10:43:58 [error] 33980#33980: *3 connect() failed (111: Connection refused) while connecting to upstream, client:server: dev.domain, request: "GET /app/login HTTP/1.1", upstream: "http://[::1]:3000/app/login", host:domain

Back to Top