How to Set up sitemap.xml on NGINX Servers?
Squirrly SEO automatically generates your sitemap when you enable the XML Sitemap settings.
On NGINX servers, you may need to add server-level rewrites to correctly set up the sitemap.xml file.
With the standard WordPress NGINX configuration (a location / block with try_files $uri $uri/ /index.php?$args;), the sitemaps load without extra rules. You need the rules below when sitemap.xml returns an NGINX 404 page. That happens when another location block catches .xml files first, for example a static files block such as location ~* \.(css|js|xml)$.
Add the following rules for Squirrly SEO sitemap in nginx.conf, inside the server block of your site:
location ^~ /sitemap {
rewrite ^/sitemap\.xml$ /index.php?sq_feed=sitemap last;
rewrite ^/sitemap-posts\.xml$ /index.php?sq_feed=sitemap-post last;
rewrite ^/sitemap-pages\.xml$ /index.php?sq_feed=sitemap-page last;
rewrite ^/sitemap-categories\.xml$ /index.php?sq_feed=sitemap-category last;
rewrite ^/sitemap-tags\.xml$ /index.php?sq_feed=sitemap-post_tag last;
rewrite ^/sitemap-archives\.xml$ /index.php?sq_feed=sitemap-archive last;
rewrite ^/sitemap-authors\.xml$ /index.php?sq_feed=sitemap-author last;
rewrite ^/sitemap-custom-taxonomies\.xml$ /index.php?sq_feed=sitemap-custom-tax last;
rewrite ^/sitemap-custom-posts\.xml$ /index.php?sq_feed=sitemap-custom-post last;
rewrite ^/sitemap-([a-z]+)\.xml$ /index.php?sq_feed=sitemap-$1 last;
try_files $uri $uri/ /index.php?$args;
}The last rewrite rule covers the other files: sitemap-home.xml, sitemap-product.xml, sitemap-news.xml and sitemap-attachment.xml. The try_files line hands every other address that starts with /sitemap to WordPress as usual, for example sitemap_index.xml or a page with the slug sitemap-guide.
The ^~ prefix tells NGINX to use this block for addresses that start with /sitemap without checking the regex locations (the ones written with ~ or ~*), so the rules work wherever you put them in the server block. Older versions of this FAQ used location ~ ([^/]*)sitemap(.*).xml$. That regex block only works when it comes before every other regex location that matches .xml files, because NGINX uses the first regex location that matches, and it also stops sitemap_index.xml from loading. Replace it with the block above.
The paginated sitemaps keep working with these rules. The sitemap index links to addresses such as sitemap-posts.xml?page=2, sitemap-custom-posts.xml?type= followed by a post type name, or sitemap-custom-taxonomies.xml?taxonomy= followed by a taxonomy name. NGINX matches the rewrite on the path only and adds the original page, type and taxonomy parameters after sq_feed, so you don’t need a separate rule for them.
If your WordPress permalinks are set to Plain, Squirrly uses addresses such as /?sq_feed=sitemap-post and you don’t need these rules.
After you reload NGINX, open https://example.com/sitemap.xml (with your own domain) and click a few of the sitemaps it lists, including sitemap-tags.xml and a page 2, to check that each one loads.
NOTE! In case you are not 100% sure where to add these rules, we recommend reaching out to your web host or server admin and asking for further assistance.
Still Need Help?
If you’ve added the rewrite rules in the correct file, and you still encounter issues, they are likely linked to other settings on your server. You can always reach out to our support team via one of the available channels whenever you need more assistance.
On an Apache server, use the rules from How to Set up sitemap.xml on Apache Servers? instead.



