# Include order and variables definition in configuration

**URL:** <https://www.ruby-forum.com/t/include-order-and-variables-definition-in-configuration/239397>\
**Category:** NGINX\
**Created:** [February 24, 2014, 11:41pm UTC](https://www.ruby-forum.com/t/include-order-and-variables-definition-in-configuration/239397 "2014-02-24T23:41:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [February 24, 2014, 11:41pm UTC](https://www.ruby-forum.com/t/include-order-and-variables-definition-in-configuration/239397/1 "2014-02-24T23:41:11Z")

</div>

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._

---

<div class="post-metadata">

**Author:** ![B.R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3be4f8/32.png) [@B.R](https://www.ruby-forum.com/u/B.R)\
**Post date:** [February 24, 2014, 11:47pm UTC](https://www.ruby-forum.com/t/include-order-and-variables-definition-in-configuration/239397/2 "2014-02-24T23:47:39Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![B.R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3be4f8/32.png) [@B.R](https://www.ruby-forum.com/u/B.R)\
**Post date:** [February 25, 2014, 12:42am UTC](https://www.ruby-forum.com/t/include-order-and-variables-definition-in-configuration/239397/3 "2014-02-25T00:42:56Z")

</div>

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.

> **[nginx](http://nginx.org/)**

---

<div class="post-metadata">

**Author:** ![B.R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3be4f8/32.png) [@B.R](https://www.ruby-forum.com/u/B.R)\
**Post date:** [February 25, 2014, 2:49am UTC](https://www.ruby-forum.com/t/include-order-and-variables-definition-in-configuration/239397/4 "2014-02-25T02:49:56Z")

</div>

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 [Module ngx\_http\_fastcgi\_module](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.

> **[nginx](http://nginx.org/)**

---

<div class="post-metadata">

**Author:** ![B.R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3be4f8/32.png) [@B.R](https://www.ruby-forum.com/u/B.R)\
**Post date:** [February 25, 2014, 1:07am UTC](https://www.ruby-forum.com/t/include-order-and-variables-definition-in-configuration/239397/5 "2014-02-25T01:07:04Z")

</div>

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._

---

<div class="post-metadata">

**Author:** ![B.R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3be4f8/32.png) [@B.R](https://www.ruby-forum.com/u/B.R)\
**Post date:** [February 25, 2014, 9:46am UTC](https://www.ruby-forum.com/t/include-order-and-variables-definition-in-configuration/239397/6 "2014-02-25T09:46:34Z")

</div>

On Tue, Feb 25, 2014 at 2:49 AM, Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Note (quote from [Module ngx\_http\_fastcgi\_module](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._
