How to use fastcgi_index?

Michael Schmarck michael.schmarck at habmalnefrage.de
Thu Nov 6 11:51:42 MSK 2008


Hi.

In my nginx.conf (of nginx 0.6.31, part of Sun's CoolStack 1.3.1), I
have:

        location ~ \.php$ {
            root           /data/www;
            fastcgi_pass   127.0.0.1:65505;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /data/www$fastcgi_script_name;
            include        fastcgi_params;
        }

In /data/www, I have a "pi" directory, containing:

--($ /opt/coolstack/nginx/conf)-- ls -l /data/www/pi
total 1
-rw-r--r--    1 webservd webservd       26 Nov  4 13:49 index.php
--($ /opt/coolstack/nginx/conf)-- cat /data/www/pi/index.php 
<?php
phpinfo();

# EOF #

When I now call http://$server/pi/, I'm shown the directory
index of the "pi" directory (because I have "autoindex on;").

What would be the proper way to have nginx "show" the
index.php, if there's one and if http://$server/$dir/ is
invoked? (I don't want to see the source code of index.php,
I want to have that interpreted by PHP.)

Do I have to add it to the "index" direcetive, like so?

        location / {
            root   /data/www;
            index  default.htm index.html index.htm index.php;
        }

This works, but is that the way it's supposed to be done?

But also adding "fastcgi_index  index.php;" to the 
"location / { … }" statement doesn't make nginx call
PHP with the index.php.

Hm.

I don't think that I understand what fastcgi_index 
should be doing.

I now changed the nginx.conf to contain:

http {
  # …
  server {
    # …
        location / {
            root   /data/www;
            index  default.htm index.html index.htm index.php;
        }

        location ~ \.php$ {
            root           /data/www;
            fastcgi_pass   127.0.0.1:65505;
            fastcgi_index  SCHNISMindex.php;
            fastcgi_param  SCRIPT_FILENAME  /data/www$fastcgi_script_name;
            include        fastcgi_params;
        }
  }
}

Effect: When http://$srv/$dir/ is invoked by the browser,
whatever is in index.php is feed to PHP and shown to
the browser.

Nice — But why is that so? I would have thought, that because
of the (in this case purposely) mis-configured fastcgi_index
parameter, it shouldn't have worked. I would have
thought, that a "SCHNISMindex.php" would have been
passed to PHP. Why is that not so?

What does fastcgi_index do? I have read (and obviously not
understood) http://wiki.codemongers.com/NginxHttpFcgiModule#fastcgi_index
of course :)

Thanks a lot,
Mchael
-- 
-- 


GMX Download-Spiele: Preizsturz! Alle Puzzle-Spiele Deluxe über 60% billiger.
http://games.entertainment.gmx.net/de/entertainment/games/download/puzzle/index.html





More information about the nginx mailing list