Include order and variables definition in configuration

B.R. reallfqq-nginx at yahoo.fr
Tue Feb 25 00:05:44 UTC 2014


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.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20140225/2ef680c5/attachment.html>


More information about the nginx mailing list