首页 文章

如何为fuelphp框架配置nginx重写规则?

提问于
浏览
0

在尝试从fuelphp框架中的控制器执行操作时,我遇到了这个问题,我从nginx获得了404消息 . 我能够看到,例如, localhost / index.php或者只是localhost,但是当我尝试访问像localhost / index.php / login / huehue这样的动作控制器时,我收到404错误 . 谁能帮我?这个应用程序目前正在使用apache,我也遇到了这个麻烦,但是当我执行时一切都很好

a2enmod重写

然后我试图搜索nginx的等效配置,我发现这样:

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

或这个:

location / {rewrite ^ /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更好的选择,而燃烧模式框架的这个问题并没有能够将这两个伟大的工具结合在一起是非常糟糕的 . 提前致谢 .

2 回答

  • 0

    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的单个参数;第三种情况在命名位置调用重写 .

  • 0

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

    error_page 404  /index.php;
    

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

    希望这有助于某人 .

相关问题