缺少尾随“/”时无法访问 Portainer。是否有可能获得与 Nginx proxy_pass 相同的行为?

Cannot access Portainer when trailing "/" is missing. Is it possible to get the same behavion as Nginx proxy_pass?

我正在尝试设置 Traefik 来替换我的 Nginx 反向代理设置。 我的域设置如下: - 我可以使用 http://example.com 访问不同的服务,并使用子路径检测我应该代理到哪个服务。

我试图用 Traefik 重新创建相同的设置。首先使用 ReplacePathRegex,然后使用 StripPrefix。我的 api 请求工作正常,但是当我尝试使用 Portainer 时,网络浏览器发出的请求省略了 /portainer 部分,这导致网络 ui 中断。

例如: 我向 http://example.com/portainer 提出请求。 我得到回应,然后连续的请求应该是这样的:http://example.com/portainer/vendor1.css 相反,它发出这样的请求: http://example.com/vendor1.css

有什么方法可以设置 Traefik 行为以完全匹配 Nginx proxy_pass

我发现这个 post 给了我一个部分解决方案:. Portainer seems to be working when I make request to http://example.com/portainer/ 通过在末尾添加“/”。 我尝试用forceSlash修复它,但它没有做出任何改变

是否可以让它在有或没有尾随“/”的情况下工作?

这是 /portainer/portainer/ 中请求的样子:

这是我当前的 Traefik 配置(我只使用 Docker):

Stripprefix 中间件用于在转发请求之前从路径中删除前缀。根据您的配置,/portainer/portainer 之后的所有内容都将被删除。 在您的情况下,它还会删除结尾的斜杠。如果你需要转发/到Portainer,那么你需要使用portainer(没有斜线)作为配置stripprefix中间件的前缀。

我找到了解决方案:https://community.containo.us/t/middleware-to-add-the-if-needed/1895

这是我必须添加到我的 portainer 容器中的 labels 以使其工作的内容:

- traefik.http.middlewares.strip-prefix.chain.middlewares=strip-prefix-1,strip-prefix-2
- traefik.http.middlewares.strip-prefix-1.redirectregex.regex=^(https?://[^/]+/[a-z0-9_]+)$$
- traefik.http.middlewares.strip-prefix-1.redirectregex.replacement=$/
- traefik.http.middlewares.strip-prefix-1.redirectregex.permanent=true
- traefik.http.middlewares.strip-prefix-2.stripprefixregex.regex=/[a-z0-9_]+

这不是理想的解决方案,因为我认为应该有更简单的方法来实现它,但暂时它满足了我的需求。