Question

Redirection error on the 2nd website configured in Nginx Virtual Blocks after adding ssl certifcate from Lets Encrypt using cerbot

Posted December 9, 2019 284 views
NginxLet's Encrypt

Hi,

Steps:

  1. Added VirtualBlock A to Nginx on Ubuntu.Site A works fine.
  2. Used certbot to add an ssl certificate from Lets Encrypt. Site A Works fine.
  3. Added Virutalock B to Nginx. Site B Works fine.
  4. Used certbot to add an ssl certificate from Lets Encrypt. Site B stops working with error as below.

“The page isn’t redirecting properly”

any help would be greatly appreciated.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hi @harishkgarg,

This might not be related to your Nginx configuration but rather to your website one.

This error usually pops up when you accidentally have a series of rewrite directives that cause an infinite redirect loop, or if your PHP code is sending bad HTTP redirects that are causing an infinite loop.

You can debug the issue by doing the following in your browser:

  • Open a new tab.
  • Open your Developer Tools (in chrome, Ctrl+Shift+I) and switch to the “Network” tab.
  • Click “Preserve log” so that your request history is not lost on each redirect.
  • Load the URL that is redirecting infinitely in your browser.
  • Look at the requests being made in the “Network” tab to identify what URLs nginx or PHP is sending back to the browser as redirects. By seeing the actual URLs your browser is trying to visit, you can usually identify the logic error that is causing the infinite loop.

If you remove the block for Site B for 443/SSL, I’ll be sure the website will start working properly again.

Please try something of the above and let me know how it goes.

Regards,
KDSys

  • Thanks for your response @KDSys

    1. I tried the Chrome Dev Tools method you suggested. I see a huge number of requests being made to my website 2 - https://bignumworks.com

    2. Here is my config file for website 2. Which lines should I remove?

    server {
    
        root /var/www/bignumworks.com/html;
        index index.html index.htm index.nginx-debian.html;
    
        server_name bignumworks.com www.bignumworks.com;
    
        location / {
            try_files $uri $uri/ =404;
        }
    
        listen [::]:443 ssl; # managed by Certbot
        listen 443 ssl; # managed by Certbot
        ssl_certificate /etc/letsencrypt/live/bignumworks.com/fullchain.pem; # managed by Certbot
        ssl_certificate_key /etc/letsencrypt/live/bignumworks.com/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 = www.bignumworks.com) {
            return 301 https://$host$request_uri;
        } # managed by Certbot
    
    
        if ($host = bignumworks.com) {
            return 301 https://$host$request_uri;
        } # managed by Certbot
    
    
        listen 80;
        listen [::]:80;
    
        server_name bignumworks.com www.bignumworks.com;
        return 404; # managed by Certbot
    }
    
    edited by MattIPv4
    • Hi @harishkgargm

      Your Nginx configuration looks perfect.

      What I suggest is checking your website/application experiencing issues. Most probably you have a redirect there somewhere causing this behavior.

      Regards,
      KDSys

Submit an Answer