trouble executing php scripts with nginx

Posted by lovesh on Server Fault See other posts from Server Fault or by lovesh
Published on 2012-09-25T21:14:30Z Indexed on 2012/09/25 21:39 UTC
Read the original article Hit count: 193

Filed under:

My nginx config looks like this

server {
        listen       80;
        server_name  localhost;

        location / {
           root /var/www;
           index index.php index.html;
           autoindex on; 
        }

        location /folder1 {
           root   /var/www/folder1;
           index  index.php index.html index.htm;
           try_files $uri $uri/ index.php?$query_string;
        }

        location /folder2 {
           root   /var/www/folder2;
           index  index.php index.html index.htm;
           try_files $uri $uri/ index.php?$query_string;
        }

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include        fastcgi_params;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

The problem with the above setup is that i am not able to execute php files. Now as per my understanding of nginx config rules, when i am in my webroot(/) which is /var/www the value of $document_root becomes /var/www so when i request for localhost/hi.php the fastcgi_param SCRIPT_FILENAME becomes /var/www/hi.php and that is the actual path of the php script. Similarly when i request for localhost/folder1/hi.php the $document_root becomes /var/www/folder1 because this is specified as the root in folder1's location block so again the fastcgi_param SCRIPT_FILENAME becomes /var/www/folder1/hi.php. But because the above configuration does not work so there is something wrong with my understanding. Please help?

© Server Fault or respective owner

Related posts about nginx