This tutorial is the second part of this article. We will go trough the following configurations:
- Add a file provider* to
- Create a config file for a central configuration for storing middlewares
- Configure a middleware chain
*file provider is another place where you can store your configuration
You will find all the required configuration files in our Git repository.
EDIT: Unfortunately there is currently an issue with embedded Gists on the Medium Desktop site (mobile works fine). You can find all our Gists here.
In order to follow along, you’ll need to read this post!
Update Traefik configuration
To setup a reusable middleware add an additional provider in the Traefik configuration file
traefik.yml (Lines 15 and 16).
Create a file for the central configuration:
Add a middleware to redirect http to https:
Mount the new
config.yml file in the docker-compose file for Traefik (line 20):
Recreate Traefik container:
docker-compose up -d
The redirection in the file provider does not work in the docker-compose for Traefik!
Use the new Middleware
As a template we use the docker-compose of Portainer from the previous article. Replace the lines 19 and 20 with following line:
The Portainer docker-compose now looks like this:
@fileinstructs Traefik to look inside
config.yml for the corresponding middleware.
So every time you want to redirect http to https, you can add the middleware
https-redirect. You can add multiple middlewares separated with a comma.
The Chain middleware enables you to define reusable combinations of other pieces of middleware. It makes reusing the same groups easier.
The Description above was stolen from here.
So let’s do this! Add some middelwares in the
default-headermiddleware sets some basic security headers.
default-whitelistmiddleware allows only internal IP addresses.
Then we add a middleware chain with the previously created middlewares:
config.yml now looks like this:
To use the chain we can add it as any other middleware:
With the central middlewares and the middleware chain it’s easy to setup multiple containers with the same configuration.
You can also add additional lables for the same settings. Here an example for Nextcloud:
gi8lino from Containeroo