nginx - 文件夹中的多个项目 Nginx
问题描述
我正在尝试配置 nginx 来处理文件夹中的不同项目。
我有一个文件夹“www”,它有很多子文件夹,每个子文件夹都是一个独立的项目,其中 .html 和其他文件具有到项目中文件的相对路径。
例如,如果您访问 www.example.com/project1,我希望提供位于 www/project1/index.html 中的 index.html 文件。project2 应该服务于 www/project2/index.html 等等。问题是这个 html 文件中的每一个都有到项目的图像和子文件夹的相对路由,问题是我不知道如何在 Nginx 中处理它。
此外,当访问 www.example.com/ 时,应提供不同的文件夹,例如 www/main/index.html(也带有相关路由)。
如何在 Nginx 中正确实现这一点?我一直在阅读文档,我可以正确地提供 .html,但图像和相对路径都是 404。
谢谢
解决方案
您可能希望像这样为每个项目配置一个位置
location /project1 {
root /<yourPath>/www/project1;
index index.html;
}
location /project2 {
root /<yourPath>/www/project2;
index index.html;
}
相关文档:
http://nginx.org/en/docs/http/ngx_http_core_module.html#location
http://nginx.org/en/docs/http/ngx_http_core_module.html#root
http://nginx.org/en/docs/http/ngx_http_index_module.html#index
推荐阅读
- vscode-settings - 如何将外部库包含到 arduino 扩展中?
- azure - Azure - WAF 和子页面访问/查看限制
- django - 在 Django 中使用 **dict 作为 create/update_or_create 方法的参数 - 不一致的异常
- css - 如何使用 [ngStyle] 覆盖离子自定义 CSS
- java - 如何在java中创建模板类文件
- linux - 从 Perl 中的 csv 文件中删除最后一列
- java - 在 @RestController 的 @PathVariable 上自定义 @JsonDeserialize
- tensorflow - 为什么使用 tensorflow2.0 相同数据集的训练准确率和验证准确率不同?
- android - 如何在滑翔中加载 tinyUrl?
- kubernetes - ETCD 向 Prometheus 认证数据