Zend Framework additional Get params with NGINX

2019-04-02 22:35发布

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;
    }
}

2条回答
做自己的国王
2楼-- · 2019-04-02 23:19

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;
}
查看更多
爷的心禁止访问
3楼-- · 2019-04-02 23:33

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;
}
查看更多
登录 后发表回答