Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a sitemap.xml that runs in 1.5 GB.

How do I serve that sitemap.xml compressed from nginx such that it will be compressed only once and then served? Probably using caching too (if possible)

Also I periodically update the sitemap.xml. So in that case it compressed site map should be invalidated and the new one compressed

share|improve this question
I'm curious if this actually works? Is the content really that dynamic? Or are you not exporting lastmod times? I'm assuming for SEO, search engines probably rate proper Sitemaps implementations over static files as well. – polynomial Oct 2 '11 at 18:13
up vote 1 down vote accepted

Afaik, virtually every crawler/search engine understands sitemap.xml.gz.

Configure whatever application generates your sitemap.xml to also gzip it, and then just have Nginx serve that pre-compressed file. In Nginx's config add something like

location /sitemap.xml.gz
    add_header Cache-Control "public, must-revalidate";

In addition to that, you might also want to add a 301 redirect from sitemap.xml to sitemap.xml.gz.

share|improve this answer

You should have http_gzip_static_module enabled. Make an pre-compressed version of file with .gz extension and remove original file. Nginx will ungzip and serve it on the fly, and if you need to update it - just update compressed one.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.