【发布时间】:2019-07-20 21:57:10
【问题描述】:
在我的 docker 主机上。使用 nginx 容器,我尝试通过使用 url 名称来反向代理多个服务来识别正确的服务(portainer、rancher)。
来自https://host1/rancher 的流量 => https/rancher-container
来自https://host1/portainer 的流量 => http://portainer-container:9000
我将 nginx 配置为使用 url rewrite 来转换 url,然后再将其发送到良好的服务。 它适用于服务搬运工。但它不适用于 rancher 2 服务。
这是我的配置:
location /rancher/ {
rewrite ^/rancher^/ /$1 break;
proxy_pass https://rancher-container;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_http_version 1.1;
}
location /portainer/ {
rewrite ^/portainer^/ /$1 break;
proxy_pass http://portainer-container:9000/;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
当我从我的 chromeDevTools 中查看时,我看到了:
GET https://host1/rancher/ 200 OK(并像这样返回索引页面):
<!DOCTYPE html>
<html>
...
<link id="vendor" rel="stylesheet" href="/assets/vendor.css">
...
<script src="/assets/vendor-ebb1f9e6b4381d69a55448a2a5d7e4c9.js"></script>
<script src="/assets/ui-72ee502ee50a84d0f416c3164137307d.js"></script>
...
获取https://host1/assets/vendor.cssnet::ERR_ABORTED 404
获取https://host1/assets/vendor-ebb1f9e6b4381d69a55448a2a5d7e4c9.jsnet::ERR_ABORTED 404
获取https://host1/assets/ui-72ee502ee50a84d0f416c3164137307d.js
我认为我的网络浏览器会尝试在 html 页面上使用“/assets/”到“https://host1/assets”等相对 URL 定义资源(css、js、img ..etc)。或者好的 url 是'https://host1/racher/assets'。
有解决办法吗?
【问题讨论】:
标签: docker nginx reverse-proxy rancher