我正在使用前端控制器开始我自己的mvc框架,这是有效的 - 所有请求都通过/index.php,它正在加载bootstrap文件,例如router.php。
但是,$ _GET不起作用,所以我的router.php文件无效。我的URL方案只是/ controller / view而省略了.php,但是由于我无法$ _GET将url传递给router.php(以加载正确的控制器和视图),因此我无法更改URL。 / p>
我到处寻找解决方案,并在stackoverflow上发现了这个类似的帖子,但是建议修复对我不起作用: https://serverfault.com/questions/231578/nginx-php-fpm-where-are-my-get-params
这是我的nginx.conf:
server {
listen 80;
server_name mvcapp;
#Remove Trailing Slash '/'
rewrite ^/(.*)/$ /$1 permanent;
root /usr/local/var/www/mvcapp/public;
index index.php;
location / {
# Neither of the below 2 lines work
#try_files $uri $uri/ /index.php?$query_string;
try_files $uri $uri/ /index.php?$args;
}
#proxy Non-static requests to nginx
location ~ \.php$ {
# Include the default fastcgi_params file included with Nginx
include /usr/local/etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
# Pass to upstream PHP-FPM;
fastcgi_pass 127.0.0.1:9000;
}
}
我对php-fpm的了解非常薄弱 - 所以也许我错过了一个fastcgi_param?
你看错了什么?
(感谢)
答案 0 :(得分:3)
如果要将URI作为get参数传递,请执行以下操作:
try_files $uri $uri/ /index.php?$request_uri;
您的index.php
会看到您使用index.php?/controller/view