Zend Framework additional Get params with NGINX

2019-04-02 23:17发布

问题:

I configured my NGINX for Zend in the following way (PHP 5.3 with fpm):

server {
root /home/page/public/;
index index.php index.html index.htm;

server_name localhost;

location / {
    try_files $uri $uri/ /index.php;
}

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

location ~ /\.ht {
    deny all;
}
}

Now i want to process additional get params like: http://web.site/index?par=1

WIth my local dev system (Apache) it works fine but not under NGINX which did'T deliver the get params.

Anny suggestions?

Edit:

Now i use the following config which seems to work but i'm not happy with it since everybody suggests "use try_files whenever possible".

location / {
    if (!-e $request_filename) {
        rewrite  /(.*)$  /index.php?q=$1  last;
        break;
    }
}

回答1:

From Nginx docs ( http://wiki.nginx.org/HttpCoreModule#try_files):

If you need args preserved, you must do so explicitly:

location / {
   try_files $uri $uri/ /index.php?$args;
}


回答2:

I use a rewrite module for this; try replacing your location / block with the following:

location / { 
    index  index.php index.html index.htm;
}   

if (!-e $request_filename) {
    rewrite ^.*$ /index.php last;
}