【发布时间】:2015-09-15 05:27:03
【问题描述】:
我有一个在 docker 容器中运行的第 3 方 ui 服务器,暴露在端口 8080 上。
似乎期望用绝对路径加载资源:http://localhost:8080/index.html,http://localhost:8080/js/some_jsfiles
等等
我想为它创建一个反向代理,让它看起来像是来自不同的路径:
https://myserver.com/stormui/index.html, https://myserver.com/stormui/js/...
第一次尝试
location /stormui/ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
#rewrite ^/stormui/(.*) /$1 break;
proxy_pass http://127.0.0.1:8080/;
}
index.html 页面加载,但浏览器仍然尝试在没有附加路径的情况下加载引用的内容,所以我在 index.html 引用的所有 javascripts 等上得到 404。
然后我尝试使用referer进行重写 位置 / {
if ($http_referer ~ "^/stormui/.*") {
rewrite ^/(.*) /stormui/$1 break;
}
root /usr/share/nginx/html;
index index.html index.htm;
...
}
那也没用。有没有办法做到这一点?
【问题讨论】:
-
生成的 index.html 是否包含 js/css 的绝对 URL?
标签: nginx proxy reverse-proxy