Welcome! Log In Create A New Profile

Advanced

Re: root works, alias doesn't

Grant
October 01, 2013 03:14AM
>> 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 /".

>> I tried both of the following with the same result:
>>
>> location / {
>> alias webalizer/;
>> }
>>
>> location ~ ^/$ {
>> alias webalizer/$1;
>> }
>
>
> For
>
> what you wish to do, you might try the following:
>
> set $rootDir /var/www/localhost/htdocs
> root $rootDir/;
> location / {
> alias $rootDir/webalizer/;
> }
>
> alias is meant for exceptional overload of root in a location block, so I
> guess its use here is a good idea.

I'm not sure what you mean by that last sentence. When should alias
be used instead of root inside of "location /"?

> However, there seems to be no environmental propagation of some $root
> variable (which may be wanted by developers to avoid confusion and unwanted
> concatenation of values in the variables tree).
> $document_root and $realpath_root must be computed last, based on the value
> of the 'root' directive (or its 'alias' overload), so they can't be used
> indeed.
>
> I'd be glad to know the real reasons of the developers behind the absence of
> environmental propagation of some $root variable.

Me too.

- Grant

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

root works, alias doesn't

Grant September 25, 2013 02:16PM

Re: root works, alias doesn't

B.R. September 25, 2013 02:28PM

Re: root works, alias doesn't

Grant September 29, 2013 01:34PM

Re: root works, alias doesn't

B.R. September 29, 2013 03:22PM

Re: root works, alias doesn't

Grant October 01, 2013 03:14AM

Re: root works, alias doesn't

Valentin V. Bartenev October 01, 2013 10:10AM

Re: root works, alias doesn't

Grant October 02, 2013 12:24PM

Re: root works, alias doesn't

Valentin V. Bartenev October 02, 2013 02:24PM

Re: root works, alias doesn't

Grant October 02, 2013 03:04PM

Re: root works, alias doesn't

Valentin V. Bartenev October 01, 2013 09:56AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 268
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready