ada*_*dev 11 proxy reverse-proxy nginx
我有一个在docker容器中运行的第三方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/;
}
Run Code Online (Sandbox Code Playgroud)
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;
...
}
Run Code Online (Sandbox Code Playgroud)
这也行不通.有没有办法做到这一点?
我在为Storm-UI设置 nginx 反向代理时遇到了类似的问题
经过一段时间的挖掘,我成功了。
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/;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1405 次 |
| 最近记录: |