Skip to content

Instantly share code, notes, and snippets.

@franciscoj
Last active June 5, 2021 18:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save franciscoj/4ba7dbbba1406f9d2b70b8d2404855fb to your computer and use it in GitHub Desktop.
Save franciscoj/4ba7dbbba1406f9d2b70b8d2404855fb to your computer and use it in GitHub Desktop.
Docker for local dev reverse proxy
version: '3'
services:
proxy:
image: traefik:v2.0 # The official Traefik docker image
network_mode: host # Allows traefik to talk to your host machine
ports:
- "80:80"
- "443:443"
- "8080:8080" # The Web UI
volumes:
# With this we ask docker to mount these files inside its file
# system to have access to them
- ${PWD}/traefik.toml:/etc/traefik/traefik.toml # Traefik static config
- ${PWD}/traefik.config.toml:/etc/traefik/traefik.config.toml # Traefik dynamic config
- ${PWD}/devcerts:/etc/certs # SSL Development certificates
[http]
[http.routers]
[http.routers.http-to-my-app]
# You can change the rules here and make it more complex. Check traefik
# docs!
rule = "Host(`my-app.com`)"
service = "my-app"
entrypoints = ["http"]
middlewares = ["redirect"]
[http.routers.https-to-my-app]
rule = "Host(`my-app.com`)"
service = "my-app"
entrypoints = ["https"]
[http.routers.https-to-my-app.tls]
[http.services]
[http.services.my-app]
[http.services.my-app.loadBalancer]
passHostHeader = true
[[http.services.my-app.loadBalancer.servers]]
# This is where your dev app lives.
url = "http://127.0.0.1:3000/"
[http.middlewares]
[http.middlewares.redirect.redirectScheme]
scheme = "https"
[tls]
[[tls.certificates]]
certFile = "/etc/certs/my-app.com+1.pem"
keyFile = "/etc/certs/my-app.com+1-key.pem"
[global]
sendAnonymousUsage = false
[log]
# If something goes wrong, changing this to `DEBUG` might help you finding
# out what happens.
level = "INFO" #DEBUG, INFO, WARN, ERROR, FATAL, PANIC
format = "common"
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.https]
address = ":443"
[providers]
# This is how you tell traefik that it has to get the dynamic config from a config file
# Note that the path is the path to the file inside Docker, not insider your machine!
# If you want do use Docker itself for this check traefik docs!
[providers.file]
filename = "/etc/traefik/traefik.config.toml"
watch = true
[api]
# With this you enable the web UI
insecure = true
dashboard = true
@rkulow
Copy link

rkulow commented Dec 29, 2019

@franciscoj: Thanks for sharing your config files.
For others, please make sure to fix the typo in line 19 of traefik.config.toml before using:
change [http.services.my-ap.loadBalancer] to [http.services.my-app.loadBalancer], otherwise search and replace would'nt find this occurrence.

@franciscoj
Copy link
Author

Thanks for the comment, I just fixed it :)

@rkulow
Copy link

rkulow commented Dec 29, 2019

Thanks for the comment, I just fixed it :)

perfect 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment