1

I am using nginx, and trying to load the site on port 80 (or root) gives 502 bad gateway error after trying to connect for a while.

When I input: netstat -ltnp | grep :80 I get the results below.

netstat command results

And here it is my nginx.conf:

#user  nginx;

# The number of worker processes is changed automatically by CustomBuild, according to the number of CPU cores, if it's set to "1"
worker_processes  4;
pid /var/run/nginx.pid;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

events {
    include /etc/nginx/nginx-events.conf;
}


http {
    include       /etc/nginx/mime.types;

    # For user configurations not maintained by DirectAdmin. Empty by default.
    include /etc/nginx/nginx-includes.conf;

    # Supplemental configuration
    #include /etc/nginx/nginx-modsecurity-enable.conf;
    include /etc/nginx/nginx-defaults.conf;
    include /etc/nginx/nginx-gzip.conf;
    include /etc/nginx/nginx-proxy.conf;
    include /etc/nginx/directadmin-ips.conf;
    include /etc/nginx/directadmin-settings.conf;
    include /etc/nginx/nginx-vhosts.conf;
    include /etc/nginx/directadmin-vhosts.conf;

        server {
        listen 80;

        root   /var/www/html;
        index index.html index.htm index.php;

        }
}

Note: any other ports than 80 works fine. Obviously 8080 and 8081 are taken, but beside those, any other ports (e.g. 8000) works fine.

Things I have tried so far: this solution, and using proxy.

What could be possibly cause this?

Community
  • 1
  • 1
Sina
  • 765
  • 1
  • 13
  • 32

1 Answers1

1

Alright, so I started commenting out all the includes, and came up to the knowing that the line below was defining another port 80 server:

include /etc/nginx/directadmin-vhosts.conf;

Therefore I manipulated this file (directadmin-vhosts.conf) instead of defining my servers in nginx.conf, and things were all good then.

Note, for some reason this command wasn't showing exactly all the port 80s that were taken:

netstat -ltnp | grep :80

Hence I used the command below instead, and that's when I realized there is somewhere else that nginx is using port 80 as well.

netstat -ltnp | grep :*

Noob mistake I reckon, but I hope this answer helps somebody out there who is struggling with the same issue.

Sina
  • 765
  • 1
  • 13
  • 32