root works, alias doesn't
Grant
emailgrant at gmail.com
Wed Oct 2 16:22:17 UTC 2013
>> >> 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/;
> }
That's true. Is alias or root preferred in this situation for performance?
- Grant
More information about the nginx
mailing list