Traefik 作为一个简单的 Http 反向代理不起作用
Posted
技术标签:
【中文标题】Traefik 作为一个简单的 Http 反向代理不起作用【英文标题】:Traefik as a simple Http Reverse Proxy not working 【发布时间】:2018-08-29 08:19:54 【问题描述】:我使用 Traefik 作为 HTTP 反向代理。我有两个使用 spring boot 创建的服务器。两台服务器都在端口8081
和8082
上正常工作
Traefik Web UI 在端口8080
中可见。
我想要的是将http://localhost:7070/
重定向到http://localhost:8081/
或http://localhost:8082/
traefik.toml 配置文件
loglevel="INFO"
defaultEntryPoints = ["http"]
[entryPoints]
[entryPoints.http]
address = ":7070"
[file]
[frontends]
[frontends.frontend1]
backend = "backend1"
[frontends.frontend1.routes.test_1]
rule = "Host: localhost"
[backends]
[backends.backend1]
[backends.backend1.LoadBalancer]
method = "drr"
[backends.backend1.healthcheck]
path = "/app/health"
interval = "60s"
[backends.backend1.servers.server1]
url = "http://127.0.0.1:8081"
weight = 1
[backends.backend1.servers.server2]
url = "http://127.0.0.1:8082"
weight = 1
[api]
[ping]
[docker]
控制台输出
INFO[2018-03-20T18:38:58+05:30] Using TOML configuration file
/home/kasun/apps/temp/traefik.toml
INFO[2018-03-20T18:38:58+05:30] Traefik version v1.5.4 built on 2018-
03-15_01:33:52PM
INFO[2018-03-20T18:38:58+05:30]
Stats collection is disabled.
Help us improve Traefik by turning this feature on :)
More details on https://docs.traefik.io/basics/#collected-data
INFO[2018-03-20T18:38:58+05:30] Preparing server http &Network:
Address::7070 TLS:<nil> Redirect:<nil> Auth:<nil>
WhitelistSourceRange:[] Compress:false ProxyProtocol:<nil>
ForwardedHeaders:0xc4202a4520 with readTimeout=0s writeTimeout=0s
idleTimeout=3m0s
INFO[2018-03-20T18:38:58+05:30] Preparing server traefik &Network:
Address::8080 TLS:<nil> Redirect:<nil> Auth:<nil>
WhitelistSourceRange:[] Compress:false ProxyProtocol:<nil>
ForwardedHeaders:0xc4202a4540 with readTimeout=0s writeTimeout=0s
idleTimeout=3m0s
INFO[2018-03-20T18:38:58+05:30] Starting server on :7070
INFO[2018-03-20T18:38:58+05:30] Starting provider *docker.Provider
"Watch":true,"Filename":"","Constraints":null,"Trace":false,
"DebugLogGen
eratedTemplate":false,"Endpoint":
"unix:///var/run/docker.sock","Domain":"","TLS":null,
"ExposedByDefault":true,"UseBindPortIP":false,"SwarmMode":false
INFO[2018-03-20T18:38:58+05:30] Starting server on :8080
INFO[2018-03-20T18:38:58+05:30] Starting provider *file.Provider
"Watch":true,"Filename":"/home/kasun/apps/temp/traefik.toml",
"Constraints":null,"Trace":false,"DebugLogGeneratedTemplate":false,
"Directory":""
INFO[2018-03-20T18:38:58+05:30] Server configuration reloaded on :7070
INFO[2018-03-20T18:38:58+05:30] Server configuration reloaded on :8080
INFO[2018-03-20T18:38:58+05:30] Server configuration reloaded on :7070
INFO[2018-03-20T18:38:58+05:30] Server configuration reloaded on :8080
WARN[2018-03-20T18:38:58+05:30] HealthCheck has failed
[http://127.0.0.1:8081]: Remove from server list
WARN[2018-03-20T18:38:58+05:30] HealthCheck has failed
[http://127.0.0.1:8082]: Remove from server list
WARN[2018-03-20T18:38:58+05:30] HealthCheck has failed
[http://127.0.0.1:8082]: Remove from server list
WARN[2018-03-20T18:38:58+05:30] HealthCheck has failed
[http://127.0.0.1:8081]: Remove from server list
当我从浏览器加载 http://localhost:7070/
时,它会给出
服务不可用
当我转到 Traefik 健康仪表板时,它会显示
谁能告诉我我在这里做错了什么?我浏览了几篇文章,但找不到正确的答案。
【问题讨论】:
Traefik 文档纯属垃圾。我也想要一个简单的答案。 【参考方案1】:我想你是在容器中运行 Træfik。
127.0.0.1 -> localhost 在容器内,而不是在本地机器中。
【讨论】:
没有。我在我的本地机器上运行它。我这里没有使用 docker。 为什么最后有一个[docker]
,可能是混淆了Traefik?
@Almar 我认为它与--docker
相同,也与--api
相同。这个 TOML 在 traefik 集群中很混乱,应该没有 TOML 吧?
TOML 不是问题,也不会让 Traefik 感到困惑以上是关于Traefik 作为一个简单的 Http 反向代理不起作用的主要内容,如果未能解决你的问题,请参考以下文章
k8s ingress-controller 之 traefik