Hi all,
Just migrated to Traefik version 3.1.1. I'm using, Docker, Docker compose, a couple of websites and nothing fancy in the config. At Traefik startup I got this error:
ERR error="error while adding rule Host(`domain.nl`,`www.domain.nl`,`domain2.nl`,`www.domain2.nl`): error while adding rule Host: unexpected number of parameters; got 4, expected one of [1]" entryPointName=web routerName=domainnl@docker`
Googled it and found enough hits, so changed my code to:
# Http section
- "traefik.http.routers.domainnl.rule=Host(`domain.nl`) || Host(`www.domain.nl`) || Host(`domain2.nl`) || Host(`www.domain2.nl`)"
- "traefik.http.routers.domainnl.entrypoints=web"
- "traefik.http.routers.domainnl.middlewares=redirect"
# Https section
- "traefik.http.routers.domainnl-secure.rule=Host(`domain.nl`) || Host(`www.domain.nl`) || Host(`domain2.nl`) || Host(`www.domain2.nl`)"
- "traefik.http.routers.domainnl-secure.entrypoints=websecure"
But I'm still getting the exact same error. Restarted containers, restarted VPS, cleared docker caches, I don't understand. What am I doing wrong?
You also got a dynamic config file with old config?
Note that you could centralize the http-to-https redirect on entrypoint and don’t need two routers, check simple Traefik example.
Hi. The entire config is in the docker compose yaml per site and the traefik.yaml for the global settings:
providers:
docker:
exposedByDefault: false
endpoint: unix:///var/run/docker.sock
network: traefik
ping: {}
api:
dashboard: true
insecure: false
debug: true
log:
level: INFO
entryPoints:
web:
address: ":80"
websecure:
address: ":443"
certificatesResolvers:
letsencrypt:
acme:
email: support@domain.io
storage: /etc/traefik/acme.json
tlsChallenge: true
Just to be sure I enclose one of the site configs:
version: "3"
services:
domain.io:
container_name: domain.io
image: nginx
restart: unless-stopped
volumes:
- ./data:/var/www/html
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- /etc/localtime:/etc/localtime:ro
networks:
- traefik
healthcheck:
test: ["CMD", "curl", "--fail", "http://localhost"]
interval: 30s
timeout: 5s
retries: 3
start_period: 10s
labels:
# Enable because disabled by default in traefik.yml
- "traefik.enable=true"
# Always redirect to https
- "traefik.http.middlewares.redirect.redirectscheme.scheme=https"
- "traefik.http.middlewares.redirect.redirectscheme.permanent=true"
# Http section
- "traefik.http.routers.domainio.rule=Host(`domain.io`) || Host(`www.domain.io`)"
- "traefik.http.routers.domainio.entrypoints=web"
- "traefik.http.routers.domainio.middlewares=redirect"
# Https section
- "traefik.http.routers.domainio-secure.rule=Host(`domain.io`) || Host(`www.domain.io`)"
- "traefik.http.routers.domainio-secure.entrypoints=websecure"
# Connect middelwares to router
- "traefik.http.routers.domainio-secure.middlewares=compression"
# All secure middlewares go here
- "traefik.http.middlewares.compression.compress=true"
# TLS configuration to be used
- "traefik.http.routers.domainio-secure.tls=true"
- "traefik.http.routers.domainio-secure.tls.certresolver=letsencrypt"
networks:
traefik:
external: true
It's been quite a while that I set this up initially, but I believe this is all config. I also replaced the acme.json already, and let Traefik re-populate that file.
When this is solved I will surely look at your centralization tip! Thanks!
Did you restart the other services/containers for the changes in their compose file labels to take effect?
I had already restarted containers, restarted the VPS, cleared docker caches and cleaned the acme.json (just to be sure).
Your question made me look at the container labels though and surprise surprise: it had the old ones. So I actually had to delete container and spin up a fresh one (i thought a docker compose down and docker compuse up -d would do the same, but it didn't).
So thanks a lot for the tip, you're a hero!