<div dir="ltr"><div class="gmail_default" style="font-size:small;color:rgb(51,51,153)">Hello,<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Sep 29, 2013 at 1:33 PM, Grant <span dir="ltr"><<a href="mailto:emailgrant@gmail.com" target="_blank">emailgrant@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
It works if I specify the full path for the alias. What is the<br>
difference between alias and root? I have root specified outside of<br>
the server block and I thought I could use alias to avoid specifying<br>
the full path again.<br></blockquote><div><br><div class="gmail_default" style="font-size:small;color:rgb(51,51,153);display:inline"><a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#alias">http://nginx.org/en/docs/http/ngx_http_core_module.html#alias</a><br>
<a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#root">http://nginx.org/en/docs/http/ngx_http_core_module.html#root</a><br><br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153);display:inline">
The docs says that the requested filepath is constructed by concatenating root + URI<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153);display:inline">That's for root.<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153);display:inline">
<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153);display:inline">The docs also say that alias replaces the content directory (so it must be absolutely defined through alias).<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153);display:inline">
By default, the last part of the URI (after the last slash, so the file name) is searched into the directory specified by alias.<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153);display:inline">
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.<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153);display:inline">
</div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I tried both of the following with the same result:<br>
<br>
location / {<br>
alias webalizer/;<br>
}<br>
<br>
location ~ ^/$ {<br>
alias webalizer/$1;<br>
}<br></blockquote><div><br><div class="gmail_default" style="font-size:small;color:rgb(51,51,153);display:inline">For</div> <div class="gmail_default" style="font-size:small;color:rgb(51,51,153);display:inline">what you wish to do, you might try the following:<br>
<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153);display:inline">set $rootDir /var/www/localhost/htdocs<br>root $rootDir/;<br>location / {<br> alias $rootDir/webalizer/;<br>}<br><br></div>
<div class="gmail_default" style="font-size:small;color:rgb(51,51,153);display:inline">alias is meant for exceptional overload of root in a location block, so I guess its use here is a good idea.<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153);display:inline">
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).<br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153);display:inline">
$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.<br><br></div><div class="gmail_default" style="font-size:small;color:rgb(51,51,153);display:inline">
I'd be glad to know the real reasons of the developers behind the absence of environmental propagation of some $root variable.<br></div></div></div><font size="1"><span style="color:rgb(102,102,102)">---<br></span><b><span style="color:rgb(102,102,102)">B. R.</span></b><span style="color:rgb(102,102,102)"></span></font>
</div></div>