我以下面的方式configuration了我的NGINX for Zend(用PHP 5.3的PHP):
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; } }
现在我想处理额外的获取参数,如: http ://web.site/index?par =1
通过我的本地开发系统(Apache),它可以正常工作,但不能在NGINX下实现。
安妮的build议?
编辑:
现在我使用下面的configuration似乎工作,但我不满意,因为大家build议“尽可能使用try_files”。
location / { if (!-e $request_filename) { rewrite /(.*)$ /index.php?q=$1 last; break; } }
来自Nginx的文档( http://wiki.nginx.org/HttpCoremodulee#try_files ):
如果你需要保存参数,你必须明确地这样做:
location / { try_files $uri $uri/ /index.php?$args; }
我使用了一个重写模块 。 尝试使用以下内容替换您的location /
区块:
location / { index index.php index.html index.htm; } if (!-e $request_filename) { rewrite ^.*$ /index.php last; }