【问题标题】:traefik does not forward requests to a "normal" (non-docker) backendtraefik 不会将请求转发到“正常”(非 docker)后端
【发布时间】:2018-01-12 09:34:20
【问题描述】:

在 docker 模式下测试 traefik - 一切正常。现在我需要使用“普通”后端,即从 traefik 控制的端口 88 将请求转发到端口 8080。但它没有按预期工作。

curl -v -H Host: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"

【问题讨论】:

    标签: traefik


    【解决方案1】:

    solved by Idez。配置必须是这样的([file] 部分丢失):

    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"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-13
      • 1970-01-01
      • 1970-01-01
      • 2021-05-10
      相关资源
      最近更新 更多