When I started to learn NGINX virtual host configurations, I had a problem to write a location. I was accessing an address and was always getting 404 error. It was when I discovered that there was ROOT and ALIAS directives.

Let’s supose I have the configuration below:

The final path will be:

That’s the reason I was getting 404 errors, because what is written on location is appended to the path specified on root. The correct form would be as follows:

On the other hand, with alias, what is written on location will be dropped, and the configuration stays like this:

The final path will be:

So that’s it… simple! The documentation can be seen on this link:
http://wiki.nginx.org/HttpCoreModule#alias

3 thoughts on “Difference between root and alias on NGINX

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.