我正在尝试配置 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;
}
Run Code Online (Sandbox Code Playgroud)
各自的文档:
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
| 归档时间: |
|
| 查看次数: |
5109 次 |
| 最近记录: |