How to serve multiple sitemap.xml in nginx?

by domenico.weimann , in category: SEO , a year ago

How to serve multiple sitemap.xml in nginx?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

Member

by zion , a year ago

@domenico.weimann 

To serve multiple sitemap.xml files in Nginx, you can use the location directive to configure different paths for each sitemap file. Here's an example:

  1. Open your Nginx configuration file. This is usually located at /etc/nginx/nginx.conf or /etc/nginx/conf.d/default.conf.
  2. Inside the server block, add separate location blocks for each sitemap file you want to serve. For example: server { ... location /sitemap1.xml { alias /path/to/sitemap1.xml; types { } default_type "text/xml"; } location /sitemap2.xml { alias /path/to/sitemap2.xml; types { } default_type "text/xml"; } location /sitemap3.xml { alias /path/to/sitemap3.xml; types { } default_type "text/xml"; } ... } In this example, we have three sitemap files: sitemap1.xml, sitemap2.xml, and sitemap3.xml. Adjust the file paths to match your actual sitemap files.
  3. Save the configuration file and exit the text editor.
  4. Run a syntax check to ensure that the configuration file doesn't contain any syntax errors: sudo nginx -t
  5. If the syntax check passes, reload the Nginx configuration to apply the changes: sudo systemctl reload nginx


After following these steps, you should be able to access the sitemap.xml files by visiting the corresponding URLs on your Nginx server, such as http://example.com/sitemap1.xml, http://example.com/sitemap2.xml, etc.