root works, alias doesn't
Valentin V. Bartenev
vbart at nginx.com
Tue Oct 1 14:09:31 UTC 2013
On Tuesday 01 October 2013 11:12:41 Grant wrote:
> >> It works if I specify the full path for the alias. What is the
> >> difference between alias and root? I have root specified outside of
> >> the server block and I thought I could use alias to avoid specifying
> >> the full path again.
> >
> > http://nginx.org/en/docs/http/ngx_http_core_module.html#alias
> > http://nginx.org/en/docs/http/ngx_http_core_module.html#root
> >
> > The docs says that the requested filepath is constructed by concatenating
> > root + URI
> > That's for root.
> >
> > The docs also say that alias replaces the content directory (so it must
> > be absolutely defined through alias).
> > By default, the last part of the URI (after the last slash, so the file
> > name) is searched into the directory specified by alias.
> > alias doesn't construct itself based on root, it's totally independent,
> > so by using that, you'll need to specify the directory absolutely, which
> > is precisely what you wish to avoid.
>
> I see. It seems like root and alias function identically within "location /".
>
Not exactly. For example, request "/favicon.ico":
location / {
alias /data/www;
}
will result in opening "/data/wwwfavicon.ico", while:
location / {
root /data/www;
}
will return "/data/www/favicon.ico".
But,
location / {
alias /data/www/;
}
will work the same way as
location / {
root /data/www;
}
or
location / {
root /data/www/;
}
wbr, Valentin V. Bartenev
More information about the nginx
mailing list