Is this how variable (set $var) inheritance works?
Maxim Dounin
mdounin at mdounin.ru
Fri Feb 3 18:10:24 UTC 2012
Hello!
On Fri, Feb 03, 2012 at 10:26:07PM +0700, Edho Arief wrote:
> (doesn't seem to be specified in documentation)
>
> My test showed:
> - anything set in server { } block is inherited:
>
> server {
> set $something /usr/share/something;
> ...
> location / {
> location /nested/ {
> # $something is set to /usr/share/something
> root $something;
> }
> }
> }
>
> - anything set in location { } block is not inherited:
>
> server {
> ...
> location /~ {
> location ~ ^/~([^/]+)(|/.*)$ {
> set $userfile /home/$1/public_html/$2;
> alias $userfile;
> location ~ \.php$ {
> include fastcgi_params;
> # $userfile is empty here
> fastcgi_param SCRIPT_FILENAME $userfile;
> fastcgi_pass 127.0.0.1:9000;
> }
> }
> }
>
>
>
> Is it correct?
Yes, this is expected behavrious. Rewrite module directives are
never inherited, and directives specified inside location are only
executed if this exact location matches.
See here for details:
http://nginx.org/en/docs/http/ngx_http_rewrite_module.html
Maxim Dounin
More information about the nginx
mailing list