- Before we begin, lets cleanup any running Docker stack
docker stack rm traefikIf you named you stack something else use your specified name. If you don't remember rundocker stack ls - Change to the
05-Middlewaresfolder - Generate a new password for our
catappby 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.ymlfile in your favorite editor and review thecatappsection - Edit the
docker-compose.auth.ymlcatappsection and add the Auth Middleware to ourcatapprouter- "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
catappdocker stack deploy -c docker-compose.auth.yml traefik - Open the Traefik Dashboard http://0.0.0.0:8080 and verify the new
test-authMiddleware is running and and assigned to thecatappservice - Open the
catappapplication in a new browser tab http://catapp.localhost - Enter the user
traefikand passwordtrainingto visit yourcatappapplication
- Before we begin, lets cleanup the HTTP stack
docker stack rm traefikIf you named you stack something else use your specified name. If you don't remember rundocker stack ls - Change to the
05-HTTPS-and-TLSfolder - Open the
docker-compose.compress.ymlfile in your favorite editor and review thecatappsection - Add the Compress Middleware to our
catappsection- "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
catappdocker stack deploy -c docker-compose.compress.yml traefik - Open the Traefik Dashboard http://0.0.0.0:8080 and verify the new
test-compressMiddleware is running and and assigned to thecatappservice - Open the
catappapplication in a new browser tab http://catapp.localhost
- Before we begin, lets cleanup the HTTP stack
docker stack rm traefikIf you named you stack something else use your specified name. If you don't remember rundocker stack ls - Change to the
05-HTTPS-and-TLSfolder - Open the
docker-compose.error.ymlfile in your favorite editor and review thecatappsection - 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
catappsection
# 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
catappdocker stack deploy -c docker-compose.error.yml traefik - Open the Traefik Dashboard http://0.0.0.0:8080 and verify the new
test-errorpagesMiddleware is running and and assigned to thecatappservice - Open the
catappapplication 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 traefikIf you named you stack something else use your specified name. If you don't remember rundocker stack ls - Change to the
05-HTTPS-and-TLSfolder - Open the
docker-compose.ratelimit.ymlfile in your favorite editor and review thecatappsection - Add the Rate Limit Middleware to our
catappsection- "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
catappdocker stack deploy -c docker-compose.ratelimit.yml traefik - Open the Traefik Dashboard http://0.0.0.0:8080 and verify the new
test-ratelimitMiddleware is running and and assigned to thecatappservice - Open the
catappapplication in a new browser tab http://catapp.localhost - Refresh the
catapppage 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 traefikIf you named you stack something else use your specified name. If you don't remember rundocker stack ls - Change to the
05-HTTPS-and-TLSfolder - Open the
docker-compose.redirect.ymlfile in your favorite editor and review thecatappsection - Next, we need to separate 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
catappsection
- "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 Environment section of Traefik
- Start Traefik and the
catappdocker stack deploy -c docker-compose.redirect.yml traefik - Open the Traefik Dashboard http://0.0.0.0:8080 and verify the new
test-redirectschemeMiddleware is running and and assigned to thecatappservice - Open the
catappapplication in a new browser tab and openyour-domainconfigured in the DNS section - You should see your
catappdomain redirect from HTTP -> HTTPS automagically.
