简体   繁体   English

基于Traefik路径的路由

[英]Traefik Path Based Routing

I have two backends I want to serve from one Host. 我有两个要从一个主机提供服务的后端。 One from host.domain.com and the other from host.domain.com/path. 一个来自host.domain.com,另一个来自host.domain.com/path。 The first frontend rule is straightforward: Host:host.domain.com . 第一个前端规则很简单: Host:host.domain.com

The second is giving me some trouble. 第二是给我带来麻烦。 Based on the documentation I believe I should be using Host:host.domain.com;PathPrefixStrip:/path . 根据文档,我相信我应该使用Host:host.domain.com;PathPrefixStrip:/path This returns a 200 on host.domain.com/path, but when I click the link to somepage.html, it sends me to host.domain.com/somepage.html, so it returns a 404. If I go directly to host.domain.com/path/somepage.html it returns a 200. The link to somepage.html behaves correctly when I go directly to host.domain.com/path/index.html. 这将在host.domain.com/path上返回200,但是当我单击指向somepage.html的链接时,它将把我发送到host.domain.com/somepage.html,因此它返回404。如果我直接转到主机.domain.com / path / somepage.html它返回200。当我直接转到host.domain.com/path/index.html时,指向somepage.html的链接正确运行。

Are my assumptions/interpretations of the documentation incorrect or is this not an issue with Traefik at all? 我对文档的假设/解释是否正确,还是Traefik根本没有问题?

This isn't really specific to traefik, any virtual path based reverse proxy that doesn't rewrite the contents of the web page returned (and few do this) have problems when the contents of that web page have absolute paths. 这不是真正针对traefik的,任何不重写返回的网页内容的基于虚拟路径的反向代理(很少这样做)都会在该网页的内容具有绝对路径时出现问题。 The web page needs to either know about the "/path" and modify all the links it gives you, or use relative links, without a leading "/". 网页需要知道“ / path”并修改它给您的所有链接,或者使用相对链接,而不能以“ /”开头。 This should be fixed within your website, web application, or hopefully a configuration for a web application. 这应该在您的网站,Web应用程序或Web应用程序的配置中修复。 Depending on the application, once reconfigured, you may need to adjust the traefik rule to just "PathPrefix" instead of "PathPrefixStrip". 根据应用程序,重新配置后,您可能需要将traefik规则调整为仅“ PathPrefix”而不是“ PathPrefixStrip”。

You should use a PathPrefix instead a PathPrefixStrip . 您应该使用PathPrefix而不是PathPrefixStrip The Strip rules remove the path before presenting it to the backend. Strip规则在将路径呈现给后端之前先删除该路径。

Since the path is stripped prior to forwarding, your backend is expected to listen on /. 由于路径是在转发之前剥离的,因此您的后端应侦听/。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM