Website Experience Intermittent Redirect Loops That Resolve Automatically

I am experiencing intermittent redirect loops on my website, which cause temporary downtime. These issues appear randomly but seem to resolve automatically without any changes on my end. I'm using NGINX for my web server and have the following configuration. Any insights on what could be causing this behavior? I have tried everything to debug but couldn't figure out. The issue appears intermittently, causing temporary downtime but resolves without any changes on my end. Looking for possible reasons and troubleshooting steps. NGINX Configuration # NGINX Cache path fastcgi_cache_path /var/www/nginx-cache levels=1:2 keys_zone=WORDPRESS:300m inactive=6h; fastcgi_cache_key "$scheme$request_method$host$request_uri"; fastcgi_cache_use_stale error timeout invalid_header http_500; # HTTP server (handles all HTTP requests) server { listen 80; listen [::]:80; server_tokens off; server_name .example.com; # Force HTTPS for non-www (HSTS compliant) if ($host = example.com) { return 301 https://example.com$request_uri; } # Force HTTPS for www if ($host = www.example.com) { return 301 https://www.example.com$request_uri; } # Deny all other hostnames return 444; } # HTTPS server (handles both www and non-www) server { listen 443 ssl http2; listen [::]:443 ssl http2; server_tokens off; server_name .example.com; root /var/www/example.com; index index.php index.html index.htm; client_max_body_size 0; ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; ssl_protocols TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:20m; ssl_session_timeout 20m; ssl_ciphers 'TLS13+AESGCM+AES128:EECDH+AES128'; error_page 404 /404.html; error_page 500 502 503 504 /50x.html; # For HTTPS non-www add_header Strict-Transport-Security 'max-age=63072000; includeSubDomains; preload' always; # Redirect non-www to www if ($host = example.com) { return 301 https://www.example.com$request_uri; } # Deny all other hostnames if ($host !~ ^(www\.)?example\.com$) { return 444; } # Rest of the configuration remains the same set $skip_cache 0; if ($request_method = POST) {set $skip_cache 1;} if ($request_uri ~* "/wp-admin/|/xmlrpc.php|/wp-.*.php|index.php|sitemap|xml") {set $skip_cache 1;} if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {set $skip_cache 1;} if ($query_string = "unapproved*") {set $skip_cache 1;} if ($cookie_woocommerce_items_in_cart = "1" ){ set $skip_cache 1;} if ($request_uri ~* "/(cart|checkout|my-account)/*$") {set $skip_cache 1;} # Block Crawlers if ($http_user_agent ~* (AhrefsBot|Bytespider|SemrushBot|MJ12bot|dataforseo|opensiteexplorer)) { return 403; } # Nginx Rewrites for Rank Math Sitemaps rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last; rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last; # rewrite ^/news/sitemap_index.xml$ /news/index.php?sitemap=1 last; # rewrite ^/news/([^/]+?)-sitemap([0-9]+)?.xml$ /news/index.php?sitemap=$1&sitemap_n=$2 last; # Block access to sensitive files location ~* wp-config\.php { return 410; } location ~ /wp-includes/.*\.php$ { deny all; return 403; } location ~* ^/ask/ { return 410; } location ~* wp-trackback\.php { return 410; } location ~* xmlrpc\.php { return 410; } location ~ /wp-admin/(load-scripts|load-styles)\.php$ { return 403; } # Custom rewrite rewrite ^/old-post/$ https://example.in/io/some-post/ permanent; # Block specific paths location ~* ^/(news|hi)/ { return 410; } # Block URLs ending with /1000 location ~ /1000$ { return 410; } # Block URL ending with number location ~ /09999709233$ { return 410; } # Block URL ending with amp location ~ /amp/$ { return 410; } # Main site location / { try_files $uri $uri/ /index.php$is_args$args; } # Secure wp-login.php location ^~ /wp-login.php { satisfy any; allow 127.0.0.1; deny all; auth_basic "Secure Area"; auth_basic_user_file /var/www/.htpasswd; fastcgi_pass unix:/run/php/php8.3-fpm.sock; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; } # Handle PHP Requests location ~* \.php$ { if ($uri !~ "^/uploads/") { fastcgi_pass unix:/run/php/php8.3-fpm.sock; } try_files $uri =404; include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass unix:/run/php/php8.3-fpm.sock; fastcgi_index index.php; fastcgi_cache_bypass $skip_cache; fastcgi_no_cache $skip_cache; fastcgi_cache WORDPRESS; fastcgi_cache_valid 200 30d; fastcgi_cache_valid 301 302 303 307 308 404 410 451 1m; add_header X-Cache $upstream_cache_status; # Security Headers add_header Strict-Transport-Security 'max-age=63072000; includeSubDomains; preload' always; add_header x-content-type-options 'nosniff'; add_header x-frame-options 'sameorigin'; add_header x-xss-protection '1'; add_header 'Referrer-Policy' 'strict-origin-when-cross-origin'; add_header 'Permissions-Policy' 'camera=(), geolocation=(), microphone=()'; add_header 'content-security-policy' 'upgrade-insecure-requests'; } # Static file caching location ~* \.(css|gif|ico|svg|webp|woff2|eot|jpeg|jpg|js|png|avif)$ { add_header Cache-Control "public,max-age=31536000,immutable"; access_log off; log_not_found off; } # Gzip Configuration gzip on; gzip_disable "msie6"; gzip_vary on; gzip_proxied any; gzip_comp_level 5; gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy; } Please let me know if you need any additional informations.

Comment (0)

You’ll be in good company