WordPress Sitemap 404 Not Found Error with Nginx
Sitemap 404 Not Found
If you are using Nginx as your web server and install the Google XML Sitemap plugin on your WordPress site, then when you submit your xml sitemap to Goolge Search Console, you may get a WordPress sitemap 404 not found error.
The Solution
The solution is simple, just copy the following lines to your nginx virtual host file. On CentOS/Redhat Server, the virtual host file usually is /etc/nginx/conf.d/example.com.conf. On Debian/Ubuntu Server, it is located at /etc/nginx/sites-available/example.com
rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml$ "/index.php?xml_sitemap=params=$2" last; rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml\.gz$ "/index.php?xml_sitemap=params=$2;zip=true" last; rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html$ "/index.php?xml_sitemap=params=$2;html=true" last; rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html.gz$ "/index.php?xml_sitemap=params=$2;html=true;zip=true" last;
Save the virtual host file and reload Nginx.
sudo systemctl reload nginx
or
sudo /etc/init.d/nginx reload
When you first installed Google XML Sitemap plugin, it will give a warning if you are using Nginx. The above rewrite rules can also be found when you go to Settings > XML-Sitemap.
Thanks..