nginx - Nginx 配置通配符第一个文件夹
问题描述
我正在努力让 nginx conf 以我们需要的方式工作。基本上在同一个域上,我们有许多应用程序,每个应用程序都在根文件夹中。当用户安装应用程序时,不可能知道文件夹的名称。
location / {
try_files $uri $uri/ /index.php?$args /index.php?q=$uri&$args;
}
location /myfiles {
try_files $uri $uri/ /myfiles/index.php?$args /myfiles index.php?q=$uri&$args;
}
如果我指定第二个文件夹,它会使 myfiles 中的应用程序正常工作,URL 可以正确解析。如果我不这样做,那么主应用程序会尝试解析 URL,但它会失败。
所以我想有类似的东西:
location /* {
try_files $uri $uri/ /$folderrequested/index.php?$args /$folderrequested/index.php?q=$uri&$args;
}
其中 * 可以是任何根文件夹,例如 myfiles、mycrm、myaccount,它们会将流量路由到该文件夹。
欢迎任何建议和想法!
解决方案
将所有应用程序根目录放在父目录中。
server {
listen .....;
server_name ....;
root /path/to/apps;
index index.php index.html;
location / {
}
location ~ \.php {
fastcgi_pass localhost:8000;
}
}
答对了。
推荐阅读
- c++ - 为什么在 C/C++ 中处理浮点字节序转换很困难?
- mysql - 在 MySQL 中'USE INDEX' 不起作用但'FORCE Index' 似乎工作正常
- java - 创建注释并将其附加到多条记录
- ios - 如何在 SwiftUI 的子视图中呈现父视图?
- python - “从 kapre.time_frequency 导入 Melspectrogram,Spectrogram”中的错误
- c# - AndroidPublisherService - Play Developer API 客户端 - 由于凭据错误,上传 aab 失败
- r - dplyr 根据字符串匹配选择列
- android - FileReader FileError 错误代码 1 NOT_FOUND_ERR(误导性)与 Android 上的 Cordova 插件 cordova-plugin-file 和 cordova-plugin-media-capture
- javascript - 为什么控制台会抛出“无法读取未定义的属性‘未定义’”?
- python - 每次在不同机器上的 numpy 中生成相同的随机矩阵