【问题标题】:Migrating Yii2 from Apache to Nginx - failed on backend app将 Yii2 从 Apache 迁移到 Nginx - 后端应用程序失败
【发布时间】:2016-10-26 19:44:18
【问题描述】:

我尝试将我的 Yii2 应用程序从使用 apache 转移到 nginx。我在单个域上使用 Yii2 高级模板,所以我遵循从 this link 的解决方案创建从 frontend/webbackend/web 的符号链接。这个解决方案在我使用 apache 时效果很好,但是当我尝试使用 nginx 时,我无法打开后端应用程序。

前端应用工作正常,但是当我尝试使用app.local/belakang 打开后端应用时,它被重定向到app.local/belakang/site/login,但仍卡在前端应用中,因此给出了[yii\web\HttpException:404] exception 'yii\base\InvalidRouteException' with message 'Unable to resolve the request "belakang/site/login".'

这是我在frontend/web 目录中的符号链接:

lrwxrwxrwx  1 vagrant vagrant   17 Jun 24 14:03 belakang -> ../../backend/web

这是我使用的 nginx vhost 配置:

server {
    charset utf-8;
    client_max_body_size 128M;

    listen 80; ## listen for ipv4

    server_name app.local;
    root        /var/www/html/frontend/web;
    index       index.php;

    location / {
        # Redirect everything that isn't a real file to index.php
        try_files $uri $uri/ /index.php$is_args$args;
    }

    # deny accessing php files for the /assets directory
    location ~ ^/assets/.*\.php$ {
        deny all;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        try_files $uri =404;
    }

    location ~* /\. {
        deny all;
    }
}

谁能帮助我从app.local/belakang 打开后端应用程序?

【问题讨论】:

  • 我为后端的 yii2 高级应用创建了特殊的子域。我认为最好为管理员设置单独的子域而不是子文件夹。

标签: php apache nginx yii2


【解决方案1】:

通过在下面添加配置自行修复它

location ^~ /belakang {
        try_files $uri $uri/ /belakang/index.php$is_args$args;

        location ~ /\.(ht|svn|git) {
            deny all;
        }

        location ~ \.php$ {
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_pass unix:/var/run/php/php5-fpm.sock;
            try_files $uri =404;
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-06-04
    • 2019-04-09
    • 1970-01-01
    • 2014-05-28
    • 2016-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多