Welcome! Log In Create A New Profile

Advanced

Re: Re[2]: Is this how variable (set $var) inheritance works?

Edho Arief
February 03, 2012 09:54PM
On Sat, Feb 4, 2012 at 8:15 AM, Max <nginxyz@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

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

Is this how variable (set $var) inheritance works?

Edho Arief February 03, 2012 10:28AM

Re: Is this how variable (set $var) inheritance works?

Maxim Dounin February 03, 2012 01:12PM

Re: Is this how variable (set $var) inheritance works?

Edho Arief February 03, 2012 01:50PM

Re: Is this how variable (set $var) inheritance works?

Edho Arief February 03, 2012 01:52PM

Re: Is this how variable (set $var) inheritance works?

Edho Arief February 03, 2012 02:00PM

Re[2]: Is this how variable (set $var) inheritance works?

Max February 03, 2012 08:16PM

Re: Re[2]: Is this how variable (set $var) inheritance works?

Edho Arief February 03, 2012 09:54PM

Re: Re[2]: Is this how variable (set $var) inheritance works?

António P. P. Almeida February 03, 2012 10:24PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 256
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