Include order and variables definition in configuration

Hello,

I am considering the following configuration:
server {
include fastcgi.conf # Default configuration coming with a Debian
package which contains a definition of the SCRIPT_FILENAME FastCGI
variable
with $document_root$fastcgi_script_name as its value

location ~^/index.php {
fastcgi_split_path_info ^(/index.php)(/.*)$;
}
}

​Will the FastCGI SCRIPT_FILENAME variable value take into account the
value of $fastcgi_script_name after fastcgi_split_path_info has been
called
or will it be resolved when the fastcgi.conf file is included?

B. R.

On Mon, Feb 24, 2014 at 11:39:39PM +0100, B.R. wrote:

Hi there,

server {
include fastcgi.conf # Default configuration coming with a Debian

location ~^/index.php {
fastcgi_split_path_info ^(/index.php)(/.*)$;
}

Will the FastCGI SCRIPT_FILENAME variable value take into account the
value of $fastcgi_script_name after fastcgi_split_path_info has been called
or will it be resolved when the fastcgi.conf file is included?

That seems fairly straightforward to check.

What does the debug log say?

Or the tcpdump of the traffic between nginx and the fastcgi server?

Or the fastcgi server logs, if you can see them?

(It’s the one that you would expect it to be, based on
fastcgi_split_path_info being useful.)

What it actually comes down to is the time at which variables are
evaluated – and in general, it’s “the first time they are needed”.

Cheers,

f

Francis D. [email protected]

Hello!

On Mon, Feb 24, 2014 at 11:39:39PM +0100, B.R. wrote:

}

}

​Will the FastCGI SCRIPT_FILENAME variable value take into account the
value of $fastcgi_script_name after fastcgi_split_path_info has been called
or will it be resolved when the fastcgi.conf file is included?

Variables are evaluated at runtime only, during processing of a
request. And the $fastcgi_script_name variable will use
fastcgi_split_path_info as found in a location where the variable
is used - that is, in a location where fastcgi_pass happens.


Maxim D.
http://nginx.org/

Hello!

On Tue, Feb 25, 2014 at 01:05:44AM +0100, B.R. wrote:

Hello Francis and Maxim,

I understand very well that $fastcgi_script_name value is defined after
fastcgi_split_path_info is called.
However I was wondering about other variables which value depend on
$fastcgi_script_name, for example when PHP’s SCRIPT_NAME has been defined
in the already included fastcgi.conf.

There is no “variables which value depend on
$fastcgi_script_name”. The fastcgi_param directive defines
parameters to be sent to FastCGI application.

    location ~ ^/index\.php {
            fastcgi_split_path_info ^(/index\.php)(/.*)$;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

}

The previous configuration seems to fail (returns 200 with blank page, no
error).

The above configuration has only one fastcgi_param in
“location ~ ^/index.php”. And there are no parameters which
include $fastcgi_script_name, so your previous question is
completely irrelevant here.

Note (quote from http://nginx.org/r/fastcgi_param):

: These directives are inherited from the previous level if and only
: if there are no fastcgi_param directives defined on the current
: level.

There are fastcgi_param directives in “location ~ ^/index.php”,
so fastcgi_params directives used on previous levels are not
inherited.


Maxim D.
http://nginx.org/

Hello Francis and Maxim,

I understand very well that $fastcgi_script_name value is defined after
fastcgi_split_path_info is called.
However I was wondering about other variables which value depend on
$fastcgi_script_name, for example when PHP’s SCRIPT_NAME has been
defined
in the already included fastcgi.conf.

Here are 2 examples:
server {
listen 80;
server_name b.cd;
try_files $uri $uri/ /index.php$uri;

    root    /var/www;
    index   index.html index.htm index.php;
    include fastcgi.conf;
    fastcgi_buffers 8 8k;

    location ~ ^/index\.php {
            fastcgi_split_path_info ^(/index\.php)(/.*)$;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

}

The previous configuration seems to fail (returns 200 with blank page,
no
error).

server {
listen 80;
server_name b.cd;
try_files $uri $uri/ /index.php$uri;

    root    /var/www;
    index   index.html index.htm index.php;
    fastcgi_buffers 8 8k;

    location /favicon.ico {
        access_log off;
        log_not_found off;
        expires 7d;
        return 204;
    }

    location ~ ^/index\.php {
            fastcgi_split_path_info ^(/index\.php)(/.*)$;
            include fastcgi.conf;
            fastcgi_param PATH_INFO $fastcgi_path_info;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
    }

}

This configuration, on the other hand, runs smoothly.

If I get the ‘variables are evaluated the first time they are needed’
statement, in the first configuration, $fastcgi_script_name was accessed
when defining SCRIPT_NAME, thus its value was wrong. Whether or not
$fastcgi_script_name value is overwritten in the location block is
another
story, though.

In the second configuration, $fastcgi_script_name is ensured to be
accessed
if and only if it been correctly defined by the previous
fastcgi_split_path_info directive, ensuring the success of the
configuration.

Am I right?

B. R.

On Tue, Feb 25, 2014 at 2:49 AM, Maxim D. [email protected]
wrote:

Note (quote from http://nginx.org/r/fastcgi_param):

: These directives are inherited from the previous level if and only
: if there are no fastcgi_param directives defined on the current
: level.

There are fastcgi_param directives in “location ~ ^/index.php”,
so fastcgi_params directives used on previous levels are not
inherited.

​Thanks Maxim. Everything said there!​


B. R.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs