【问题标题】:nginx + php-fpm - php works except cannot use $_GETnginx + php-fpm - php 工作,除了不能使用 $_GET
【发布时间】:2013-09-09 00:15:58
【问题描述】:

我正在滚动我自己的 mvc 框架,从一个前端控制器开始,它正在工作 - 所有请求都通过 /index.php,它正在加载引导文件,例如 router.php。

但是,$_GET 不工作,所以我的 router.php 文件不工作。我的 URL 方案将只是 /controller/view 省略 .php,但我还不能更改 URL,因为我不能 $_GET 将 URL 传递给 router.php(以加载正确的控制器和视图)。

我到处搜索解决方案,并在 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?

你看错了什么?

(谢谢)

【问题讨论】:

    标签: url nginx get php


    【解决方案1】:

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

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

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

    【讨论】:

    • 感谢 Mohammad,是的,这就是我在之前的评论中所写的,解决了这个问题……但是 Stackoverflow 不允许我在 48 小时内发布我自己的问题的答案,所以我的答案被埋没了“小字”评论。我已经勾选了你的答案,因为它是相同的并且是正确的答案,这对于访问这个问题的其他人来说会更加明显。非常感谢您的回复。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-04
    • 2017-03-21
    • 2012-05-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多