Bobcares

Steps to Fix ERR_TOO_MANY_REDIRECTS in Nginx

by | Jan 11, 2025

Learn how to fix ERR_TOO_MANY_REDIRECTS in Nginx. As part of our Server Management Service, Bobcares answers all your questions.

Overview
  1. How to Fix ERR_TOO_MANY_REDIRECTS in Nginx?
  2. Common Causes of ERR_TOO_MANY_REDIRECTS
  3. Solutions to Resolve ERR_TOO_MANY_REDIRECTS
  4. Best Practices to Avoid Redirect Loops
  5. Conclusion

How to Fix ERR_TOO_MANY_REDIRECTS in Nginx?

The ERR_TOO_MANY_REDIRECTS error occurs when the server enters a redirect loop, continuously sending requests between URLs without resolution. In an Nginx web server setup, this issue often arises due to configuration errors, SSL settings, or conflicts with other services like Apache.

err_too_many_redirects nginx

Common Causes of ERR_TOO_MANY_REDIRECTS

1. If Nginx and Apache are configured with redirects, the rules may conflict, creating a loop.

2. Incorrect SSL certificates or settings can cause redirect loops, especially if HTTP and HTTPS are mismanaged.

3. An incorrect server_name directive in the Nginx configuration can result in improper redirects.

4. Serving some resources (e.g., images, scripts) over HTTP while enforcing HTTPS for others can create inconsistencies.

5. Misconfigured settings in Cloudflare, such as SSL encryption mode, can cause loops.

6. Cached redirect information can lead to persistent redirect loops even after fixes.

7. Redirecting all HTTP traffic to HTTPS, including already redirected HTTPS traffic, can create a loop.

Solutions to Resolve ERR_TOO_MANY_REDIRECTS

1. Check Nginx Configuration

Ensure the configuration includes proper redirect rules:

server {
listen 80;
server_name yourdomain.com;
return 301 https://$host$request_uri;
}

This redirects all HTTP traffic to HTTPS. Avoid additional conflicting redirects elsewhere.

2. Configure Separate Server Blocks

Set up separate server blocks for HTTP and HTTPS to manage traffic effectively:

server {
listen 80;
server_name www.example.com example.com;
return 301 https://$server_name$request_uri;
}

server {
listen 443 ssl;
server_name www.example.com example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

location / {
root /home/website/public;
index index.html index.htm;
proxy_pass http://unix:/run/gunicorn.sock;
include proxy_params;
}
}

The first block handles HTTP-to-HTTPS redirection.

The second block manages HTTPS traffic and SSL configurations.

3. Review SSL Settings

Verify the SSL certificate installation.

Ensure the ssl_certificate and ssl_certificate_key paths are correct.

Also, check for mixed SSL/TLS protocols or ciphers.

4. Address Mixed Content

Scan the website for hardcoded HTTP URLs and update them to HTTPS. This prevents unnecessary redirects when resources are requested.

5. Adjust Cloudflare Settings

If using Cloudflare, switch the SSL encryption mode to Full or Full (Strict) to avoid redirect conflicts.

6. Clear Cache

Clear the browser cache and cookies.

Access the site in incognito mode or use a different browser to confirm the fix.

7. Reset .htaccess File

If using Apache alongside Nginx, check and reset the .htaccess file. Remove conflicting redirect rules to avoid redundancy.

8. Test and Validate Configurations

Furthermore, use tools like SSL Labs to verify SSL setups and ensure redirects work correctly.

Best Practices to Avoid Redirect Loops

Always test Nginx configurations after making changes using nginx -t.

Use clear and minimal redirect rules.

Avoid hardcoded URLs in website code.

Regularly update third-party plugins and services to prevent conflicts.

[Want to learn more? Reach out to us if you have any further questions.]

Conclusion

By addressing the potential causes and following these solutions, we can effectively resolve the ERR_TOO_MANY_REDIRECTS error in the Nginx setup.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF