0

Below is my current nginx config.

    server {
        listen 80 default_server;
        server_name _;
        return 307 https://$host$request_uri;
    }

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

        server_name localhost;

        # Protect against the BEAST attack by not using SSLv3 at all. If you need to support older browsers (IE6) you may need to add
        # SSLv3 to the list of protocols below.
        ssl_protocols              TLSv1.2;

        ssl_certificate      /etc/nginx/ssl.crt;
        ssl_certificate_key  /etc/nginx/ssl.key;

        location / {
            proxy_pass http://localhost:80; # TODO: replace port if app listens on port other than 80
            
            proxy_set_header Connection "";
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

All has been working well, but I recently added the first 'server' block hoping to redirect my url to https:// whenever a http:// version of the URL is visited, but I am getting an 'ERR_TOO_MANY_REDIRECTS' message when visiting the URL in the browser.

My application's port is on 80 within an Azure Container.

Any help would be appreciated!

c0rdii
  • 124
  • 1
  • 12
  • 1) Run this command: `curl -I http://yourdomain.com`. You should see an HTTP **Location** header. Is the new location (redirect) correct? 2) Add the **follow** option: `curl -I -L HTTP://yourdomain.com`. Review the redirects to see why they are looping. – John Hanley Jul 28 '21 at 19:06
  • Notice this line **proxy_pass http://localhost:80**. Is the proxied application detecting that the original scheme is HTTPS and redirecting? This typically means processing **X-Forwarded-Proto** – John Hanley Jul 28 '21 at 19:08

0 Answers0