简体   繁体   English

Apache 代理背后的 Traefik

[英]Traefik behind Apache proxy

I would like to ask for some help, I have been working with Traefik for 2-3 months, we created an infrastructure with Docker Swarm, took 4 dedicated servers in our cluster and used Traefik as reverse proxy for the containers with a domain.我想寻求一些帮助,我已经与 Traefik 合作了 2-3 个月,我们使用 Docker Swarm 创建了一个基础设施,在我们的集群中使用了 4 个专用服务器,并使用 Traefik 作为具有域的容器的反向代理。

A few days ago our IT broke and had to recreate it, we got a virtual machine, which is on a dedicated server and handles bunch of VMs too, and here comes the problem.几天前,我们的 IT 崩溃了,不得不重新创建它,我们有一个虚拟机,它位于专用服务器上,也处理大量 VM,问题来了。 This VM does not have any public IP address, it is behind an apache proxy which handles all the incoming requests on 80 and forwards to the VM where the Traefik runs.这个虚拟机没有任何公共 IP 地址,它位于一个 apache 代理后面,该代理处理 80 上的所有传入请求并转发到运行 Traefik 的虚拟机。

My problem is that our IT was working with Traefik which was connected directly to the internet with a public IP, but I can not configure Traefik to work with behind this Apache proxy, I always get the minimal error message: 404 page not found.我的问题是我们的 IT 正在使用 Traefik,它使用公共 IP 直接连接到互联网,但我无法配置 Traefik 以在此 Apache 代理后面使用,我总是收到最小的错误消息:找不到 404 页面。

The VM runs CentOS. VM 运行 CentOS。

If anybody had the same problem and managed a solution please reply, I hope Traefik can work behind Apache proxy.如果有人遇到同样的问题并解决了解决方案,请回复,我希望 Traefik 可以在 Apache 代理后面工作。 Maybe we just lack some domain/hostname configuration on this VM but I still don't know what to do.也许我们只是在这个 VM 上缺少一些域/主机名配置,但我仍然不知道该怎么做。

Apparently the Apache in front of traefik is not forwarding the Host header correctly to traefik.显然,traefik 前面的 Apache 没有将Host标头正确转发到 traefik。

In order to proxy your requests to the correct backend, traefik uses the standard HTTP header Host which basically is the hostname that the end user requested (what he typed in his browser).为了将您的请求代理到正确的后端,traefik 使用标准的 HTTP 标头Host ,它基本上是最终用户请求的主机名(他在浏览器中输入的)。

If you put apache in front of that and add a proxy rule like the following:如果您将 apache 放在前面并添加如下代理规则:

ProxyPass / x.y.z.w
ProxyPassReverse / x.y.z.w

Where xyzw is the IP address of traefik, the Host header will be rewritten by apache to be xyzw .其中xyzwxyzw的 IP 地址, Host头将被 apache 重写为xyzw

That means that the original Host requested by the user would be lost and traefik would be enable to proxy correctly.这意味着用户请求的原始Host将丢失,并且 traefik 将能够正确代理。

In order to make Apache preserve the Host header coming from the client when forwarding calls to a proxy, you need to add the following configuration:为了让 Apache 在将调用转发到代理时保留来自客户端的Host标头,您需要添加以下配置:

ProxyPreserveHost On

Right after the ProxyPass directives.ProxyPass指令之后。

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

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