Is this how variable (set $var) inheritance works?
Edho Arief
edho at myconan.net
Sat Feb 4 02:53:22 UTC 2012
On Sat, Feb 4, 2012 at 8:15 AM, Max <nginxyz at mail.ru> wrote:
>
> This feature/bug is especially confusing when you use variables
> inside root and alias directives, because the nested location blocks
> will inherit the root and alias contents (unless specifically set),
> which will have any uninitialized inherited variable names replaced
> with "", so "/home/$variable/abc/$dir/" would become "/home//abc//".
>
At least this makes nested location useless for cases like this.
Instead of one regex with captures (and then use nested location), I
had to do this instead:
location /~ {
location ~ ^/~([^/]+)/(.+\.php)$ {
alias /home/$1/public_html/$2;
if (!-f $request_filename) { return 404; }
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass 127.0.0.1:9000;
}
location ~ ^/~([^/]+)(|/.*)$ {
alias /home/$1/public_html/$2;
index index.html;
}
}
Or use map (and since it's currently impossible to do non-simple regex
capture, I had to use two maps):
map $uri $user {
~^/~(?P<user1>[^/]+)(|/.*)$ $user1;
}
map $uri $file {
~^/~[^/]+(?P<file1>|/.*)$ $file1;
}
server {
...
location /~ {
location ~ ^ {
alias /home/$user/public_html/$file;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $request_filename;
fastcgi_pass 127.0.0.1:9000;
}
}
}
}
--
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
More information about the nginx
mailing list