Questions about root and alias directives

Valentin V. Bartenev vbart at nginx.com
Fri Jan 20 16:30:05 UTC 2017


On Friday 20 January 2017 12:15:30 Nikolaos Milas wrote:
> Hello,
> 
> I need a config which includes multiple different physical paths.
> 
> So I have:
> 
>     server {
> 
>          listen [::]:80;
>          ...
>          root   /var/webs/wwwmain/www/;
> 
>          index index.php index.html index.htm;
> 
>          ...
> 
>          location / {
>              try_files $uri $uri/ /index.php?$args;
>          }
> 
>          location /museum/ {
>              root /var/webs/wwwmuseum/;
>          }
> 
>          ...
> 
>     }
> 
> Now, when I request "http://www.example.com/museum/", the above config 
> produces a request for the following path:
> 
>     /var/webs/wwwmuseum/museum/index.php
> 
> I think this is the expected result, according to the documentation.
> 
> If I change the last part to use an alias directive:
> 
>          location /museum/ {
>              alias /var/webs/wwwmuseum/;
>          }
> 
> then the evaluated path becomes:
> 
>     /var/webs/wwwmain/www/museum/index.html
> 
> The alias directive does not seem to have any effect. (Why is that so?)
> 
[..]

The answer to your question is likely in the parts of the configuration
that you've skipped.

Please note, that the "index" directive produces internal redirects.

In the second case, it looks like your request is redirected to
"/museum/index.html" and then handled by some other location.

  wbr, Valentin V. Bartenev



More information about the nginx mailing list