【发布时间】:2021-09-12 07:37:29
【问题描述】:
我正在尝试使用 nginx 反向代理特定的位置规范,如下所示:
server {
listen 80;
server_name example.com;
location /example {
proxy_pass http://localhost:8080/test;
}
}
现在,当我尝试访问 http://example.com/example/css/styles.css 的资源时,我希望它尝试访问 http://localhost:8080/test/css/styles.css。但可惜 - 我从 nginx 得到 404。
当我尝试访问 http://example.com/example 时,它会显示 http://localhost:8080/test 上的内容(所以我知道基本 url 段正在工作)减去从相对 url 导入该页面的任何内容(例如样式和 JS 文件)
如何让反向代理处理子 url 段?
【问题讨论】:
-
在
location和proxy_pass参数末尾添加斜线。 -
@IvanShatsky 这似乎有效,谢谢!
标签: nginx reverse-proxy