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:
1 2 3 |
location /imagens { root /home/heitor/public_html/app/imagens; } |
The final path will be:
1 |
/home/heitor/public_html/app/imagens/imagens |
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:
1 2 3 |
location /imagens { root /home/heitor/public_html/app; } |
On the other hand, with alias, what is written on location will be dropped, and the configuration stays like this:
1 2 3 |
location /imagens { alias /home/heitor/public_html/app/imagens; } |
The final path will be:
1 |
/home/heitor/public_html/app/imagens |
So that’s it… simple! The documentation can be seen on this link:
http://wiki.nginx.org/HttpCoreModule#alias
Thank you for this post.
You’re very welcome… take some time to read the others too.
Best regards!
Thank you bro. understood very simply.