首页 > 解决方案 > Nginx config - 为什么在我添加“location = /”后没有提供 Yii2 应用程序?

问题描述

我已经配置并运行了一段时间的 Nginx。它正在处理 3 个应用程序。最重要的是应用程序#1。它由三个模块组成:帐户、参与者和管理员。因此,这些地址允许不同类型的用户登录应用程序: domain.com/account/logindomain.com/participant/login或者domain.com/admin/login 主页domain.com也由同一个应用程序处理。Nginx 配置非常简单,可以做到这一点:

location / {
    try_files $uri $uri/ /index.php?$args;
}
root $rootPath;
index index.html index.php;
# PHP
location ~ \.php$ {
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    include fastcgi_params;
    try_files $uri /index.php?$args;
}

感谢这个主页和模块由 Yii2 处理。

我认为这不应该是相关的,但是在 nginx 中的位置/application2/ application3. 一个是 php Zend 应用程序,另一个是 php 和 javascript 应用程序。

现在我需要用 Wordpress 单页机替换主页。所需的解决方案是:

为了处理 Wordpress 页面,我添加了一个部分location = /来将主地址重定向到 Wordpress 应用程序。但我无法为 PHP 添加嵌套位置,因为我收到此错误:location "/(.+.php$)" cannot be inside the exact location "/"

所以我改变了方法。我已将全局根设置为 Wordpress 路径:root $wpPath;并为帐户、参与者和管理模块添加了位置:

location /account {
    root $rootPath;
    if (-f $request_filename) {
        break;
    }

    # process PHP here
    location ~ /account/(.+\.php$) {
        alias $rootPath/$1;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }
}

主页(Wordpress)工作得很好。但是 Yii2 应用程序模块(如 /aaccount)返回 404 - 未找到。上面的设置有什么问题?

标签: nginxnginx-location

解决方案


推荐阅读