简体   繁体   English

nginx + php-fpm-php可以工作,但不能使用$ _GET

[英]nginx + php-fpm - php works except cannot use $_GET

I'm rolling my own mvc framework starting with a front controller, which is working - all requests go through /index.php, which is loading bootstrap files eg router.php. 我正在从前端控制器开始滚动自己的mvc框架,该控制器正在运行-所有请求都通过/index.php,后者正在加载引导文件,例如router.php。

However, $_GET isn't working, so my router.php file isn't working. 但是,$ _ GET不起作用,所以我的router.php文件不起作用。 My URL scheme will simply be /controller/view with .php omitted, but as yet I can't change URLs because I can't $_GET the url to pass to router.php (to load the correct controller and view). 我的URL方案将只是/ controller / view,省略了.php,但是由于我无法$ _GET将该URL传递给router.php(以加载正确的控制器和视图),因此我无法更改URL。

I have searched everywhere for solutions and found this similar post on stackoverflow, but it's recommended fix doesn't work for me: https://serverfault.com/questions/231578/nginx-php-fpm-where-are-my-get-params 我到处搜索了解决方案,并在stackoverflow上找到了类似的帖子,但是建议修复不适用于我: https : //serverfault.com/questions/231578/nginx-php-fpm-where-are-my-get -参数

Here's my nginx.conf: 这是我的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;
     }

}

My knowledge of php-fpm is very weak - so perhaps I am missing a fastcgi_param? 我对php-fpm的了解非常薄弱-所以也许我错过了fastcgi_param?

What do you see wrong? 你怎么看错?

(thanks) (谢谢)

If you want to pass the URI as a get parameter, do something like this: 如果要将URI作为get参数传递,请执行以下操作:

try_files $uri $uri/ /index.php?$request_uri;

Your index.php will see as if you used index.php?/controller/view 您的index.php就像您使用index.php?/controller/view

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM