nginx 反向代理到一组基于 http 引用的 URL 中带有附加路径的页面? [英] nginx reverse proxy to a set of pages with an additional path in the URL based on http referer?
问题描述
我有一个在 docker 容器中运行的 3rd-party ui 服务器,在端口 8080 上公开.
I have a 3rd-party ui server running in a docker container, exposed on port 8080.
似乎期望以绝对路径加载资源:http://localhost:8080/index.html
, http://localhost:8080/js/some_jsfiles
代码>等
It seems to expect to load resources with an absolute path: http://localhost:8080/index.html
, http://localhost:8080/js/some_jsfiles
etc.
我想为它创建一个反向代理,让它看起来像是来自不同的路径:
I want to create a reverse proxy to it so it looks like it is coming from a different path:
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.
The index.html page loads, but the browser still tries to load the refered content without the additional path, so I get a 404 on all the javascripts etc referenced from index.html.
然后我尝试使用referer进行重写位置/{
Then I tried to use referer to do the rewrite location / {
if ($http_referer ~ "^/stormui/.*") {
rewrite ^/(.*) /stormui/$1 break;
}
root /usr/share/nginx/html;
index index.html index.htm;
...
}
那也没有用.有没有办法做到这一点?
That didn't work, either. Is there a way to do this?
推荐答案
我在为 Storm-UI
挖掘了一段时间后,我开始工作了.
After digging for sometime, I got it working.
server {
listen 80;
server_name example.com;
location ^~ /css/ {
rewrite /(.*) /storm-ui/$1;
}
location ^~ /js/ {
rewrite /(.*) /storm-ui/$1;
}
location ^~ /templates/ {
rewrite /(.*) /storm-ui/$1;
}
location ^~ /api/ {
rewrite /(.*) /storm-ui/$1;
}
location ~ ^/topology(.*) {
rewrite /(.*) /storm-ui/$1;
}
location /storm-ui/ {
proxy_redirect / /storm-ui/;
#proxy_pass http://<STORM_MASTER_IP/HOSTNAME>:<PORT>/;
proxy_pass http://10.14.23.10:8080/;
}
}
这篇关于nginx 反向代理到一组基于 http 引用的 URL 中带有附加路径的页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!