I'm using Traefix 2.x in docker container. I would like to setup a dozen or so simple static conversions. For Example:
Host1.domain.com:80 -> 192.168.0.10:8080
Host1.domain.com:90 -> 192.168.0.10:8090
Host2.domain.com:80 -> 192.168.0.10:9090
Host4.domain.com:80 -> 192.168.0.11:8080\admin
Hello,
Do you have a problem, a question? How we can help you?
docker-compose.yml
version: "3.7"
services:
traefik:
image: traefik:v2.1.6
ports:
- "80:80"
- "90:90"
- "8080:8080"
command:
# https://docs.traefik.io/v2.1/operations/api/#insecure
- --api.insecure
# https://docs.traefik.io/v2.1/routing/entrypoints/
- --entryPoints.web.address=:80
- --entryPoints.foo.address=:90
# https://docs.traefik.io/v2.1/providers/file/
- --providers.file.directory=/conf/
- --providers.file.watch=true
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./conf/:/conf/
/conf/dyn.yml
# https://docs.traefik.io/v2.1/routing/overview/
http:
# https://docs.traefik.io/v2.1/routing/routers/#configuring-http-routers
routers:
host1:
rule: Host(`host1.domain.com`)
entryPoints:
- web
service: host1_svc
host1_foo:
rule: Host(`host1.domain.com`)
entryPoints:
- foo
service: host1_foo_svc
host2:
rule: Host(`host2.domain.com`)
entryPoints:
- web
service: host2_svc
host4:
rule: Host(`host4.domain.com`)
entryPoints:
- web
service: host4_svc
middlewares:
- add_admin
# https://docs.traefik.io/v2.1/routing/services/#configuring-http-services
services:
host1_svc:
loadBalancer:
servers:
- url: 192.168.0.10:8080
host1_foo_svc:
loadBalancer:
servers:
- url: 192.168.0.10:8090
host2_svc:
loadBalancer:
servers:
- url: 192.168.0.10:9090
host4_svc:
loadBalancer:
servers:
- url: 192.168.0.11:8080
# https://docs.traefik.io/v2.1/middlewares/overview/
middlewares:
# https://docs.traefik.io/v2.1/middlewares/addprefix/
add_admin:
addPrefix:
prefix: /admin
Documentation:
- https://docs.traefik.io/v2.1/getting-started/concepts/
- https://docs.traefik.io/v2.1/getting-started/quick-start/
- https://docs.traefik.io/v2.1/getting-started/configuration-overview/
- https://docs.traefik.io/v2.1/providers/file/
- https://docs.traefik.io/v2.1/routing/overview/
- https://docs.traefik.io/v2.1/routing/entrypoints/
- https://docs.traefik.io/v2.1/routing/routers/#configuring-http-routers
- https://docs.traefik.io/v2.1/routing/services/#configuring-http-services
- https://docs.traefik.io/v2.1/middlewares/overview/
- https://docs.traefik.io/v2.1/middlewares/addprefix/
Thanks Idez,
I have the same requirement as the first post.
Your solution does not work for me but I don't know why.
My error is "internal server error" through http and "404 page not found" through https
#Traefik.yaml
providers:
docker:
endpoint: "unix:///var/run/docker.sock"
network: "traefik" # Custom docker network
exposedByDefault: false # Only expose explicitly enabled containers
file:
directory: "/etc/traefik/"
watch: true
entryPoints:
unsecure:
address: ":80"
secure:
address: ":443"
api:
dashboard: true
insecure: true
log:
level: DEBUG
# docker-compose.yaml
version: '3.7'
services:
################################################################################
traefik:
image: "traefik"
container_name: "traefik"
restart: always
ports:
- "80:80"
- "443:443"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /home/pi/docker/traefik/:/etc/traefik/
networks:
- traefik
labels:
#Super important!
- "traefik.enable=true"
- "traefik.http.routers.traefik.rule=Host(`traefik.dockerpi.local`)"
- "traefik.http.services.traefik.loadbalancer.server.port=8080"
#############################################################################
[...]
networks:
traefik:
external: true
And finally my file for the static servers: (I basically copy/pasted your proposal, but stating a plain IP w/o https:// in front gave me a parsing error. I tried //IP and https:// both parsed well, but no resolving)
# https://docs.traefik.io/v2.1/routing/overview/
http:
# https://docs.traefik.io/v2.1/routing/routers/#configuring-http-routers
routers:
host1:
rule: Host(`test.dockerpi.local`)
entryPoints:
- unsecure
- secure
service: host1_svc
# https://docs.traefik.io/v2.1/routing/services/#configuring-http-services
services:
host1_svc:
loadBalancer:
servers:
- url: https://10.1.0.10:91