【问题标题】:How to configure nginx rewrite rules for fuelphp framework?如何为fuelphp框架配置nginx重写规则?
【发布时间】:2017-06-15 04:22:44
【问题描述】:

我在尝试从 Fuelphp 框架中的控制器执行操作时遇到了这个问题,我从 nginx 收到 404 消息。我能够看到,例如localhost/index.php 或只是 localhost,但是当我尝试访问 localhost/index.php/login/huehue 之类的操作控制器时,我收到 404 错误。谁能帮我?这个应用程序目前在 apache 中运行,我在这里也遇到了这个问题,但是当我执行时一切都很好

a2enmod 重写

然后我尝试搜索 nginx 的等效配置,发现如下:

位置 /{ try_files $uri $uri/ /index.php?$args /index.php?q=$request_uri }

或者这个:

位置/{
重写 ^ /index.php?/$request_uri;}

但他们没有为我工作。我花了几个小时试图找出原因。这是我网站的实际 vhost 文件配置:

server {
        listen 80;
        listen [::]:80;
        root /var/www/nginx/goutmeet;
        index index.php index.html index.htm index.nginx-debian.html;

        server_name goutmeet.local www.goutmeet.local;

        location / {
        try_files $uri $uri/ /index.php?$args  /index.php?q=$request_uri @handler;
        }
 location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }
location @handler {
                rewrite ^ /index.php?/$request_uri;
        }
}

我很想知道如何解决这个问题,因为有时使用 nginx 是比 apache 更好的选择,而在使用 fuelphp 框架时遇到这个问题并且不能同时使用这两个很棒的工具是很糟糕的。 提前致谢。

【问题讨论】:

    标签: php nginx web frameworks fuelphp


    【解决方案1】:

    try_files 指令可以有一个默认操作。你有三个!请参阅this document 了解更多信息。

    选择一个:

    try_files $uri $uri/ /index.php?$args;
    try_files $uri $uri/ /index.php?q=$request_uri;
    try_files $uri $uri/ @handler;
    

    我不知道哪个是适合您的应用程序的默认操作。它们都将请求发送到 PHP 控制器,但使用不同的参数集。

    第一种情况传递查询字符串;第二种情况传递一个包含请求 URI 的参数;第三种情况在指定位置调用重写。

    【讨论】:

    • 抱歉,三个都试了,结果还是一样。不,别忘了重新启动/重新加载 nginx。感谢您的帮助
    【解决方案2】:

    我找到了解决此问题的方法,只需将此行添加到配置文件:

    error_page 404  /index.php;
    

    我知道这不是最好的解决方案,但它是唯一对我有用的方法。我认为这是可以接受的,因为所有路由都应该由框架而不是 Web 服务器管理。

    希望这对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-30
      • 1970-01-01
      • 1970-01-01
      • 2012-08-25
      相关资源
      最近更新 更多