root works, alias doesn't

B.R. reallfqq-nginx at
Sun Sep 29 19:20:35 UTC 2013


On Sun, Sep 29, 2013 at 1:33 PM, Grant <emailgrant at> 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.

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 tried both of the following with the same result:
> location / {
>     alias webalizer/;
> }
> location ~ ^/$ {
>     alias webalizer/$1;
> }


​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.​
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

I'd be glad to know the real reasons of the developers behind the absence
of environmental propagation of some $root variable.
*B. R.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list