Skip to main content

nginx + Docker: Redirect vs. Location

· 2 min read
Stephan Hochdörfer

Whilst preparing and testing our Docusarus instance, I realized that the RSS feed URL used by our old blog system did not work anymore because Docusaurus generates the content in a different way.

At first, I thought it is easy: Simply redirect the /blog/rss url to /blog/rss.xml. I added the redirect rule to our nginx configuration and tested it. Sadly, in our hosting setup, the solution did not work. Because nginx (and Docusaurus) is running in a Docker container and Traefik is responsible for the SSL termination, nginx is not aware of the exposed URL and port. Since I haven't configured a fixed hostname and nginx is running on port 8080 in the container, nginx did a redirect to port 8080. That is not behavior I wanted.

Whilst thinking about it, I came up with the idea to use a Location directive to expose the real file via the old location and that worked fine:

location = /blog/rss {
try_files $uri.xml =404;
root /usr/share/nginx/html;
}

In this case, I am fine with the final solution. Since the old rss URL is not exposed anymore and only RSS feed readers use it, this should not have any negative SEO effects (e.g. duplicate content), I guess. We will find out.