Nginx Gives 502 Error but config should be correct; Please I need advise on how to debug the issue?

I have a CentOS 8 (fedora) server running and I'm trying to run my Django Webapp on it through Nginx

It runs on port 8000, and I want to access it on my browser through nginx (so port 80?)

These commands on the server itself This shows my webapp HTML page fine curl http://127.0.0.1:8000 curl http://0.0.0.0:8000

but these show me the Nginx 502 Bad Gateway page curl http://0.0.0.0 curl http://127.0.0.1

No errors in the nginx log files

This is my nginx.config:

events {
    worker_connections 1024;
}

http {
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

        access_log  /var/log/nginx/access.log  main;
        error_log   /var/log/nginx/error.log;

        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
        keepalive_timeout   65;
        types_hash_max_size 2048;

        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;

        server_tokens               off;
        server {
            listen 80;
            server_name $hostname; # I tried this with an '_' also no help

            location / {
                proxy_pass http://0.0.0.0:8000; # also tried with 127.0.0.1
                proxy_set_header Host $host;
            }
        }
}

Running nginx -T shows the config has been loaded

Any advise on what to look for? (perhaps my firewall is blocking it somehow? idk)

Kind regards

I'm trying to get my webpage working through Nginx

Looks like it was a firewall issue, I needed to open the port to accept messages

iptables -I INPUT 1 -i eth0 -p tcp --dport 8000 -j ACCEPT

Back to Top