[Solution] RankMath Sitemap Not Working on Nginx Server
Are you facing difficulty in enabling your website sitemap through RankMath WordPress plugin on an Nginx web server? If yes, then this is the post to ready.
RankMath is an awesome SEO WordPress plugin that helps website authors publish SEO-optimized blog posts.
While setting up new WordPress websites on an Nginx Server, I found that RankMath Sitemap is not working and was seeing the below message on WP Dashboard:
Since you are using an NGINX server, you may need to add the following code to your configuration file if your Sitemap pages are not loading. If you are unsure how to do it, please contact your hosting provider.
# START 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; # END Nginx Rewrites for Rank Math Sitemaps
So if you are facing this issue, then there are possible 2 ways you can get this fixed and then solve RankMath Sitemap issue on Nginx server.
Contact Web hosting Provider
If you don’t manage the web hosting yourself, then just open a support ticket with them and ask them to add the above code to your website’s Nginx config file.
They should be able to do that for you without any issue.
Also ready: Get Free Linux Web Server for Lifetime
Do It Yourself
So if you manage your own VPS or web server, then you can do this yourself very easily. You should be having some basic Linux Operating system skills.
Below are the simple steps:
If you have a Nginx web server, then all the related configuration files are present at /etc/nginx.
We are interested in our website configuration file that will be something like /etc/nginx/sites-enabled/www.example.com.conf.
1. Make backup of your file in case anything goes wrong:
$ sudo cp -p /etc/nginx/sites-enabled/www.example.com.conf /etc/nginx/sites-enabled/www.example.com.conf.bckup
2. Now you can open the file with any command line editor and can paste the lines provided by RankMath, just before the closing of the server block.
Tip: Go at the end of the file and look for “}”.
$ sudo vi /etc/nginx/sites-enabled/www.example.com.conf
Nginx website configuration file looks like below:
3. Once you have saved the file, make sure your Nginx configuration is still valid by running the below command. If there will be any error, this command will show it.
$ nginx -t
4. Now, just go to your website and see if RankMath sitemap is working or not. If it is still not working, just reload the nginx service like below:
$ sudo systemctl reload nginx
So we saw how to fix the RankMath sitemap issue for a WordPress website running on the Nginx web server.
I hope you are able to resolve your issue after following this tutorial. If you are facing any problems, please let us know through comments and if you would like to get more such articles, just subscribe to our free newsletter.