How to use two different ports for frontend and backend with the same domain name

I am very new to django and nginx and trying to host my application using nginx as server. I am able to setup the frontend with domain name and 80 as the port but i am unable to setup backend with the domain name serving on port 8000. But when i use the IP address it seems to work fine but not with the domain name. I have been trying since two days and nothing seems to work . Any help would be much appreciated.

Frontend Config

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

include snippets/snakeoil.conf;
server_name example.com;

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

server {
    listen 8000;
    server_name example.com;
    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;
    }
}

maybe it's silly, but have you checked the server ports? Entry rules and that you are allowed access through port 8000?

Back to Top