nginxhttpscertbot

NGINX HTTPS not redirecting properly


I followed Cerbot's instructions to get a HTTPS certificate for NGINX in my Debian server for a domain, but the HTTPS is not redirecting properly.

I got the following in etc/nginx/conf.d/app.conf:

server {
    server_name mnpd.khkm.dev www.mnpd.khkm.dev;
    # listen 8080;
    server_tokens off;
    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }
    location / {
        # return 301 https://mnpd.khkm.dev$request_uri;
        proxy_pass http://mnpd.khkm.dev;
    }

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mnpd.khkm.dev/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mnpd.khkm.dev/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = mnpd.khkm.dev) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    listen [::]:80;
    server_name mnpd.khkm.dev www.mnpd.khkm.dev;
    return 404; # managed by Certbot
}

In Chrome, when I go to https://mnpd.khkm.dev/, I get:

mnpd.khkm.dev redirected you too many times.
Try deleting your cookies.
ERR_TOO_MANY_REDIRECTS

I found this Stack Overflow answer where I looked at the "Network" tab in the web console and saw that the page is constantly being redirected to https://mnpd.khkm.dev/. The NGINX configuration should be listening to port 443 for the HTTPS, so why isn't it loading and constantly being redirected? (I expect the default NGINX page to be loaded.)


Solution

  • I had to remove:

    location / {
        # return 301 https://mnpd.khkm.dev$request_uri;
        proxy_pass http://mnpd.khkm.dev;
    }
    

    from my etc/nginx/conf.d/app.conf file.

    This was answered by a user in the Unix & Linux forums which also has more details.