Debugging Persistent "Too Many Redirects" Errors with Large XML Sitemap Protocol Files in Our Generator

Author
Olivia Taylor Author
|
3 weeks ago Asked
|
68 Views
|
2 Replies
0

hey folks,

we've been running our 'Free XML Sitemap Generator' for a while now, and it's been pretty solid for most users. but lately, with some really large sites, we're hitting a wall, and it's impacting their technical SEO efforts.

the main issue:

  • users trying to generate sitemaps for sites with hundreds of thousands, sometimes millions, of URLs are frequently getting "too many redirects" or sometimes just a 500 internal server error when trying to fetch the generated sitemap file.
  • this isn't during the generation process itself (that part is handled asynchronously and seems to complete), but specifically when the user tries to download or view the final sitemap.xml.

what we've already done/checked:

  • our server is NGINX + PHP-FPM. we've bumped up php_memory_limit, max_execution_time, and NGINX's proxy_read_timeout significantly.
  • we're generating sitemaps in chunks (sitemap index files) to adhere to the XML sitemap protocol limits (50k URLs per file, 50MB per file).
  • we're using GZIP compression for the generated files directly from NGINX.
  • checked for any hidden NGINX rewrite rules or PHP redirects that might be looping โ€“ nothing obvious found.
  • verified file permissions and ownership for the sitemap output directory.
  • we've tried direct file serving vs. serving through a PHP script โ€“ both exhibit similar issues under high load/large files.

the puzzling part is smaller sitemaps (under ~200k URLs total, across multiple index files) work flawlessly. it's only when the total number of linked sitemap files in the sitemap index gets really high that these redirect loops or 500s start appearing inconsistently. we're wondering if there's some obscure NGINX or PHP-FPM configuration limit we're missing related to serving a high number of static files referenced by a single index, or perhaps a subtle aspect of the XML sitemap protocol implementation we're overlooking.

any thoughts on how to debug this further for large-scale XML sitemap protocol delivery? or common pitfalls with NGINX serving a huge number of static files referenced by an index file?

thanks in advance!

2 Answers

0
MD Alamgir Hossain Nahid
Answered 3 weeks ago

I understand how frustrating it can be to debug persistent "too many redirects" or 500 errors, especially when your core generation process is solid and it only manifests with large-scale XML sitemap protocol implementations. We've certainly encountered similar challenges with high-volume technical SEO deployments.

The fact that smaller sitemaps work perfectly points towards resource exhaustion or specific configuration limits that only become apparent under significant load, likely related to NGINX's handling of numerous static file requests or PHP-FPM's interaction during the serving phase, even if it's just a gateway.

  • NGINX File Handling & Caching: For serving many static files, ensure your NGINX open_file_cache directive is appropriately configured in your http or server block. Increase max and set a reasonable inactive timeout. This helps NGINX efficiently manage file descriptors for frequently accessed files. Also, verify worker_rlimit_nofile in your NGINX main configuration to ensure workers can open enough file descriptors.
  • PHP-FPM & NGINX Interaction: Even if you're serving static files, if PHP-FPM is involved in the initial request routing or error handling, it can impact the outcome. Revisit request_terminate_timeout in your PHP-FPM pool configuration. If NGINX is reverse proxying to PHP-FPM for the sitemap (even if it's just to check existence or log), ensure fastcgi_read_timeout and fastcgi_buffers in NGINX are generous. The "too many redirects" can sometimes be a default NGINX behavior when a proxied backend (like PHP-FPM) times out or returns an unexpected response, leading NGINX to try and redirect to an error page.
  • System-Level File Descriptors: Beyond NGINX's worker_rlimit_nofile, check the global system limits for open file descriptors (ulimit -n for the NGINX user, and sysctl fs.file-max). Serving hundreds of thousands or millions of URLs across many sitemap files could hit these limits even if NGINX is configured correctly.
  • Reduce NGINX Processing Overhead: If files are truly static, ensure NGINX is serving them directly without unnecessary PHP processing. A common pattern for redirect loops is a missing file causing NGINX to pass to PHP, which then tries to serve it, fails, and redirects, creating a loop. Double-check your try_files directives.
  • Consider External Storage/CDN: For extremely large sitemaps, especially if public access is frequent, offloading these files to an object storage solution like Amazon S3, Google Cloud Storage, or Backblaze B2, and serving them via a CDN (e.g., Cloudflare, CloudFront), can significantly alleviate server load and potential NGINX/PHP-FPM bottlenecks. This also provides better global distribution and reduces latency for users.

Have you had a chance to monitor system-level metrics like file descriptor usage, CPU load, and I/O wait during the periods these errors occur, specifically when attempting to download the large sitemap indexes?

0
Olivia Taylor
Answered 3 weeks ago

MD Alamgir Hossain Nahid, man, how many of these did we *think* we checked but maybe not deep enough... especially the `open_file_cache` and `ulimit` stuff. good call on the NGINX timeouts when it passes to PHP-FPM too, ngl that's often a hidden snag.

Your Answer

You must Log In to post an answer and earn reputation.