← Back to front page

Posted on in Technology, Ubuntu

There are a lot of guides on the web that instruct you to set up your Nginx FastCGI sites like this for Zend Framework or similar frameworks, where a single index.php script handles all requests:

server {
        listen 8080;
        root /var/www/public;
        index index.php;

        try_files $uri /index.php;

        location ~ \.php$ {
                fastcgi_pass unix:/tmp/php-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
}

The problem here is that the query string is lost. The FastCGI process is passed an empty QUERY_STRING variable.

It's easy to fix this by changing the try_files directive as follows:

try_files $uri /index.php?$query_string;

Now the query string is retained and passed correctly to FastCGI. As a result, Zend Framework will also be able to parse it properly.

PS. If you use this configuration, remember to protect your user uploads, so that nobody can upload and execute an arbitrary PHP script.

2 Comments
dev 19.7.2012 14:43:39

thx a lot, you saved my life! works perfectly

Khurram Fraz 1.8.2012 09:36:43

Many thanks it helped me a lot. :) :) :)

Comments are closed.