nginx - Nginx config - 为什么在我添加“location = /”后没有提供 Yii2 应用程序?
问题描述
我已经配置并运行了一段时间的 Nginx。它正在处理 3 个应用程序。最重要的是应用程序#1。它由三个模块组成:帐户、参与者和管理员。因此,这些地址允许不同类型的用户登录应用程序:
domain.com/account/login
,domain.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 提供的主页
domain.com
- Yii2 应用程序模块像以前一样工作,因此所有
/participant
,/account
和/admin
位置都由index.php
at提供服务$rootPath
- 2 个其他应用程序在
domain.com/application2
和domain.com/application3
.
为了处理 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 - 未找到。上面的设置有什么问题?
解决方案
推荐阅读
- visual-studio - 如何在颤动/飞镖扩展中禁用蓝色警告下划线标志?
- c - 如果子线程被套接字读取阻塞,如何通过管道通知主线程?
- python - 为什么 for 循环中定义的子图表现不一致?('numpy.ndarray' 对象没有属性'plot')
- php - Laravel SQLSTATE[HY000] [1049] 未知数据库 + PHP 工匠迁移
- javascript - 向下滑动汉堡菜单
- angular - 将 http 响应映射到类型参数中的对象数组
- scrapy - 响应在 Scrapy Shell 中有效,但在代码中无效
- c# - Google Closure Compiler 中的错误 - 访问 Google Closure Compiler Service API 时发生错误,HTTP 状态代码为“MethodNotAllowed”
- typescript - 打字稿 - 强制值成为接口的属性
- sql - 错误:带有“ON”部分的 JOIN 的 SQL 子字符串