Home > Mobile >  nginx: 502 bad gateway if /index.html is not in URL
nginx: 502 bad gateway if /index.html is not in URL

Time:02-06

i don't understand what i'm doing wrong so i hope somebody can help :)

When i access http://10.0.0.54/index.html i get the right page but if i try to access http://10.0.0.54 instead of showing the index file it redirects me to https://10.0.0.54 showing error 502 bad gateway.

This is the configuration /etc/nginx/sites-available/default

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html/salvaderi;

        index index.html;

        server_name _;

        location ~ /.well-known/acme-challenge {
                allow all;
                root /var/www/html/salvaderi;
        }

        location / {
                root /var/www/html/salvaderi;
                index index.html;
        }
}

I am running nginx 1.18.0 on ubuntu 22.04

i tried changing parameters inside location /{} but i always get the same result. I also changed the root directory and made sure permission where set right. Searching on for the solution i saw other people having problems about PHP and FastCGI but i am not using it.

CodePudding user response:

Your configuration about to be right.

Possible there is some kind of proxy or load-balancer is placed between you and nginx you configuring since you got redirect to HTTPS whether there is no any redirection instructions in your config and, in the same time, there is no listen 443 ssl in config, but you still got response on HTTPS request.

I'd check next:

  • Is 10.0.0.54 in fact IP of your server?
  • Is there any return 301, return 302 or rewrite instructions in your nginx config (the better way is to dump config with nginx -T command and look over).
  • Didn't you previously have configured some redirects that may have been cached by your web client previously? Try to send GET request with curl instead of web browser (if browser been used for tests).
  • Related