- Before we begin, lets cleanup any running Docker stack
docker stack rm traefik
If you named you stack something else use your specified name. If you don't remember rundocker stack ls
- Change to the
05-Middlewares
folder - Generate a new password for our
catapp
by runningecho $(htpasswd -nb traefik training) | sed -e s/\\$/\\$\\$/g
- Every
$
in the password needs to have double$$
to escape the characters correctly.
Run the htpasswd
command
echo $(htpasswd -nb traefik training) | sed -e s/\\$/\\$\\$/g
traefik:$apr1$.zPbdVg8$LcHeyCZElH.JfxkxxlMPI.
- Open the
docker-compose.auth.yml
file in your favorite editor and review thecatapp
section - Edit the
docker-compose.auth.yml
catapp
section and add the Auth Middleware to ourcatapp
router- "traefik.http.middlewares.test-auth.basicauth.users=traefik:$$apr1$$.zPbdVg8$$LcHeyCZElH.JfxkxxlMPI."
- Update the Router to point to the new Middleware
- "traefik.http.routers.catapp.middlewares=test-auth"
- Start Traefik and the
catapp
docker stack deploy -c docker-compose.auth.yml traefik
- Open the Traefik Dashboard http://0.0.0.0:8080 and verify the new
test-auth
Middleware is running and and assigned to thecatapp
service - Open the
catapp
application in a new browser tab http://catapp.localhost - Enter the user
traefik
and passwordtraining
to visit yourcatapp
application
- Before we begin, lets cleanup the HTTP stack
docker stack rm traefik
If you named you stack something else use your specified name. If you don't remember rundocker stack ls
- Change to the
05-HTTPS-and-TLS
folder - Open the
docker-compose.compress.yml
file in your favorite editor and review thecatapp
section - Add the Compress Middleware to our
catapp
section- "traefik.http.middlewares.test-compress.compress=true"
- Update the router to include the Compress Middleware
- "traefik.http.routers.catapp.middlewares=test-auth,test-compress"
- Start Traefik and the
catapp
docker stack deploy -c docker-compose.compress.yml traefik
- Open the Traefik Dashboard http://0.0.0.0:8080 and verify the new
test-compress
Middleware is running and and assigned to thecatapp
service - Open the
catapp
application in a new browser tab http://catapp.localhost
- Before we begin, lets cleanup the HTTP stack
docker stack rm traefik
If you named you stack something else use your specified name. If you don't remember rundocker stack ls
- Change to the
05-HTTPS-and-TLS
folder - Open the
docker-compose.error.yml
file in your favorite editor and review thecatapp
section - Add the Error Page service below the
catapp
. We are using the Traefik Custom Error Page service check out the Repo for more details how to modify the Error pages.
# Error Page service
error:
image: guillaumebriday/traefik-custom-error-pages
labels:
- "traefik.enable=true"
- "traefik.http.routers.error.rule=Host(`error.localhost`)"
- "traefik.http.routers.error.service=error"
- "traefik.http.services.error.loadbalancer.server.port=80"
- "traefik.http.routers.error.entrypoints=web"
- Add the Error Page Middleware to our
catapp
section
# Error Pages Middleware
- "traefik.http.middlewares.test-errorpages.errors.status=400-599"
- "traefik.http.middlewares.test-errorpages.errors.service=error"
- "traefik.http.middlewares.test-errorpages.errors.query=/{status}.html"
- Update the router to include the Error Page middleware
- "traefik.http.routers.catapp.middlewares=test-auth,test-compress,test-errorpages"
- Start Traefik and the
catapp
docker stack deploy -c docker-compose.error.yml traefik
- Open the Traefik Dashboard http://0.0.0.0:8080 and verify the new
test-errorpages
Middleware is running and and assigned to thecatapp
service - Open the
catapp
application in a new browser tab http://catapp.localhost - Let's produce a 404 error to see our error page in actions. Open a new browser tab http://catapp.localhost/broken
- Before we begin, lets cleanup the HTTP stack
docker stack rm traefik
If you named you stack something else use your specified name. If you don't remember rundocker stack ls
- Change to the
05-HTTPS-and-TLS
folder - Open the
docker-compose.ratelimit.yml
file in your favorite editor and review thecatapp
section - Add the Rate Limit Middleware to our
catapp
section- "traefik.http.middlewares.test-ratelimit.ratelimit.average=2"
- Update the router to include the Rate Limit middleware
- "traefik.http.routers.catapp.middlewares=test-auth,test-compress,test-ratelimit"
- Start Traefik and the
catapp
docker stack deploy -c docker-compose.ratelimit.yml traefik
- Open the Traefik Dashboard http://0.0.0.0:8080 and verify the new
test-ratelimit
Middleware is running and and assigned to thecatapp
service - Open the
catapp
application in a new browser tab http://catapp.localhost - Refresh the
catapp
page quickly to see the Rate Limit error
This section we need your DNS settings again from Section 04-HTTPS-TLS
We will use the DNS settings to test the HTTP -> HTTPS redirect. Ensure your DNS settings are configured in the docker-compose.redirect.yml
- Before we begin, lets cleanup the HTTP stack
docker stack rm traefik
If you named you stack something else use your specified name. If you don't remember rundocker stack ls
- Change to the
05-HTTPS-and-TLS
folder - Open the
docker-compose.redirect.yml
file in your favorite editor and review thecatapp
section - Next, we need to seperate the two entrypoints for HTTP and HTTPS. First, we relable HTTP
# Routers
- "traefik.http.routers.catapp.rule=Host(`<your-domain-here>`)"
- "traefik.http.routers.catapp.entrypoints=web"
- "traefik.http.routers.catapp.middlewares=redirect"
- Relabel the entrypoint labels for HTTPS using
catapp-secure
- "traefik.http.routers.catapp-secure.rule=Host(`<your-domain-here>`)"
- "traefik.http.routers.catapp-secure.entrypoints=websecure"
- "traefik.http.routers.catapp-secure.tls.certresolver=myresolver"
- "traefik.http.routers.catapp-secure.middlewares=test-auth,test-compress,test-errorpages,test-ratelimit"
- Add the Redirect Scheme middleware to our
catapp
section
- "traefik.http.middlewares.test-redirectscheme.redirectscheme.scheme=https"
- "traefik.http.middlewares.test-redirectscheme.redirectscheme.permanent=true"
- Update your domain name in
- "traefik.http.routers.catapp.rule=Host(
)"
and here- "traefik.http.routers.catapp-secure.rule=Host(
)"
- Add your DNS tokens to the Enviornment section of Traefik
- Start Traefik and the
catapp
docker stack deploy -c docker-compose.redirect.yml traefik
- Open the Traefik Dashboard http://0.0.0.0:8080 and verify the new
test-redirectscheme
Middleware is running and and assigned to thecatapp
service - Open the
catapp
application in a new browser tab and openyour-domain
configured in the DNS section - You should see your
catapp
domain redirect from HTTP -> HTTPS automagically.