首页 > 解决方案 > 文件夹中的多个项目 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。

谢谢

标签: nginx

解决方案


您可能希望像这样为每个项目配置一个位置

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


推荐阅读