【发布时间】:2023-03-09 17:19:01
【问题描述】:
在 nginx 根目录下我们有这样的文件:
- test\
image.jpg
index.html
- ...
在 index.html 中有指向 image.jpg 的链接:
<img src='image.jpg'>
在标准 Nginx 配置中,我们有这样的行 (http://nginx.org/ru/docs/http/ngx_http_core_module.html#try_files)
server {
server_name example.com;
...
try_files $uri $uri/index.html;
}
对于 URL http://example.com/test/index.html(和 http://example.com/test/),一切都会正常工作,因为相对路径的基础是 http://example.com/test/,并且我们在此文件夹中有 image.jpg。
http://example.com/test 页面将显示,但没有图像。
在这种情况下,最好的解决方案是什么?
【问题讨论】:
-
在这种情况下,最好的解决方案是使用
index index.html;指令而不是try_files。在这种情况下,nginx 将从/test重定向到/test/
标签: url nginx relative-path