Kenneth Falck's Blog

Fix empty Nginx FastCGI query strings

Posted on 2011-06-19 by Kenneth Falck

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.