Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Traefik as a simple Http Reverse Proxy not working

I am using Traefik as HTTP reverse proxy. I have two servers created using spring boot. Both servers are working properly on port 8081 and 8082

Traefik web UI is visible in port 8080.

What I wanted is to redirect http://localhost:7070/ to http://localhost:8081/ or http://localhost:8082/

traefik.toml config file

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]

console output

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 

When I load http://localhost:7070/ from the browser it gives

Service Unavailable

when I go to Traefik health dashboard it displays enter image description here

Can anybody tell me what I am doing wrong here? I went through a few articles but unable to find the correct answer.

like image 675
Kasun Kariyawasam Avatar asked Mar 20 '18 13:03

Kasun Kariyawasam


1 Answers

I suppose your are running Træfik in a container.

127.0.0.1 -> localhost inside the container, not in your local machine.

like image 92
ldez Avatar answered Sep 23 '22 07:09

ldez