nginx + php-fpm-php可以工作,但不能使用$ _GET [英] nginx + php-fpm - php works except cannot use $_GET

查看:58
本文介绍了nginx + php-fpm-php可以工作,但不能使用$ _GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从前端控制器开始运行自己的mvc框架,该控制器正在运行-所有请求都通过/index.php,后者正在加载引导文件,例如router.php.

但是,$ _ GET不起作用,所以我的router.php文件不起作用.我的URL方案将只是/controller/view,省略了.php,但是由于我无法$ _GET将该URL传递给router.php(以加载正确的控制器和视图),因此我无法更改URL. /p>

我到处搜索了解决方案,并在stackoverflow上找到了类似的帖子,但是建议修复不适用于我: https://serverfault.com/questions/231578/nginx-php- fpm-哪里是我的参数

这是我的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吗?

您怎么看?

(谢谢)

解决方案

如果要将URI作为get参数传递,请执行以下操作:

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

您的index.php看起来就像您使用index.php?/controller/view

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.

However, $_GET isn't working, so my router.php file isn't working. 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).

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

Here's my 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?

What do you see wrong?

(thanks)

解决方案

If you want to pass the URI as a get parameter, do something like this:

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

Your index.php will see as if you used index.php?/controller/view

这篇关于nginx + php-fpm-php可以工作,但不能使用$ _GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆