traefik不会将请求转发给“正常”(非停泊者)后端

时间:2018-01-12 09:34:21

标签: traefik

在码头模式下经过测试的traefik - 一切都很顺利。现在我需要使用“正常”后端,意味着来自端口88的转发请求,由traefik控制到端口8080.但它不能按预期工作。

curl -v -H主持人:myhost 127.0.0.1:88(未找到,预计whoami回答)

$ curl -v -H Host:myhost  127.0.0.1:88
* Rebuilt URL to: 127.0.0.1:88/
*   Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 88 (#0)
> GET / HTTP/1.1
> Host:myhost
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 404 Not Found
< Content-Type: text/plain; charset=utf-8
< X-Content-Type-Options: nosniff
< Date: Fri, 12 Jan 2018 09:13:27 GMT
< Content-Length: 19
<
404 page not found
* Connection #0 to host 127.0.0.1 left intact
  • traefik以./traefik2 --logLevel=DEBUG --debug -c traefik.toml
  • 执行
  • 后端是sudo docker service create -d --name whoami --constraint=node.role==manager --publish 8080:80 --replicas 1 emilevauge/whoami

有什么想法吗?

traefik.toml

debug=true
logLevel = "DEBUG"

[traefikLog]
filePath = "tl.txt"

[accessLog]
filePath = "al.txt"

[entryPoints]
  [entryPoints.http]
  address = ":88"

[frontends]
  [frontends.frontend1]
  backend = "backend1"
  [frontends.frontend1.routes.backend1]
  rule = "Host:myhost"

[backends]
  [backends.backend1]
    [backends.backend1.servers.server1]
    url = "http://127.0.0.1:8080"

curl 127.0.0.1:8080(docker emilevauge / whoami,按预期工作)

$ curl 127.0.0.1:8080
Hostname: 9134668598ed
IP: 127.0.0.1
IP: 10.255.0.7
IP: 10.255.0.8
IP: 172.18.0.3
GET / HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: curl/7.47.0
Accept: */*

$ cat al.txt

192.168.99.1 - - [12/Jan/2018:09:03:39 +0000] "GET / HTTP/1.1" - - - "curl/7.57.0" 1 - - 0ms
192.168.99.1 - - [12/Jan/2018:09:04:03 +0000] "GET / HTTP/1.1" - - - "curl/7.57.0" 2 - - 0ms
192.168.99.1 - - [12/Jan/2018:09:12:19 +0000] "GET / HTTP/1.1" - - - "curl/7.57.0" 3 - - 0ms
127.0.0.1 - - [12/Jan/2018:09:13:27 +0000] "GET / HTTP/1.1" - - - "curl/7.47.0" 4 - - 0ms

$ cat tl.txt

time="2018-01-12T09:03:35Z" level=info msg="Using TOML configuration file /home/cluster/traefik.toml
"
time="2018-01-12T09:03:35Z" level=info msg="Traefik version v1.5.0-rc4 built on 2018-01-04_02:28:22P
M"
time="2018-01-12T09:03:35Z" level=info msg="
Stats collection is disabled.
Help us improve Traefik by turning this feature on :)
More details on: https://docs.traefik.io/basic/#collected-data
"
time="2018-01-12T09:03:35Z" level=debug msg="Global configuration loaded {"LifeCycle":{"RequestAccep
tGraceTimeout":0,"GraceTimeOut":0},"GraceTimeOut":0,"Debug":true,"CheckNewVersion":true,"SendAnonymo
usUsage":false,"AccessLogsFile":"","AccessLog":{"file":"al.txt","format":"common"},"TraefikLogsFile"
:"","TraefikLog":{"file":"tl.txt","format":"common"},"LogLevel":"DEBUG","EntryPoints":{"http":{"Netw
ork":"","Address":":88","TLS":null,"Redirect":null,"Auth":null,"WhitelistSourceRange":null,"Compress
":false,"ProxyProtocol":null,"ForwardedHeaders":{"Insecure":true,"TrustedIPs":null}}},"Cluster":null
,"Constraints":[],"ACME":null,"DefaultEntryPoints":["http"],"ProvidersThrottleDuration":2000000000,"
MaxIdleConnsPerHost":200,"IdleTimeout":0,"InsecureSkipVerify":false,"RootCAs":null,"Retry":null,"Hea
lthCheck":{"Interval":30000000000},"RespondingTimeouts":null,"ForwardingTimeouts":null,"Web":null,"D
ocker":null,"File":null,"Marathon":null,"Consul":null,"ConsulCatalog":null,"Etcd":null,"Zookeeper":n
ull,"Boltdb":null,"Kubernetes":null,"Mesos":null,"Eureka":null,"ECS":null,"Rancher":null,"DynamoDB":
null,"ServiceFabric":null,"Rest":null,"API":null,"Metrics":null,"Ping":null}"
time="2018-01-12T09:03:35Z" level=info msg="Preparing server http &{Network: Address::88 TLS:<nil> R
edirect:<nil> Auth:<nil> WhitelistSourceRange:[] Compress:false ProxyProtocol:<nil> ForwardedHeaders
:0x1cb52950} with readTimeout=0s writeTimeout=0s idleTimeout=3m0s"
time="2018-01-12T09:03:35Z" level=info msg="Starting server on :88"

1 个答案:

答案 0 :(得分:0)

solved by Idez。配置必须是这样的(错过[文件]部分):

defaultEntryPoints = ["http"]

debug=true
logLevel = "DEBUG"

[traefikLog]
filePath = "tl.txt"

[accessLog]
filePath = "al.txt"

[entryPoints]
  [entryPoints.http]
  address = ":88"

[file]

[backends]
  [backends.backend1]
    [backends.backend1.servers.server1]
    url = "http://127.0.0.1:8080"


[frontends]
  [frontends.frontend1]
  backend = "backend1"
    [frontends.frontend1.routes.test_1]
    rule = "Host:myhost"