404 page not found using traefik and wordpress

Hello,

I just started looking into Traefik a couple of days ago, and I'm still looking into how to configure it. Basically I want to host 2 wordpress websites and use Traefik as a reverse proxy. This is my docker-compose.yml

services:
  traefik:
    image: traefik
    container_name: traefik
    hostname: traefik
    restart: unless-stopped
    command:
      - "--log.level=INFO"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.myresolver.acme.httpchallenge=true"
      - "--certificatesresolvers.myresolver.acme.email=my@email.here"
      - "--certificatesresolvers.myresolver.acme.httpchallenge.entrypoint=web"
      - "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
    environment:
      - PUID=1001
      - PGID=1001
    ports:
      - 80:80
      - 443:443
      - 8080:8080
    volumes:
      - traefik:/letsencrypt
      - /var/run/docker.sock:/var/run/docker.sock

  domain1.com:
    image: wordpress
    container_name: domain1.com
    hostname: domain1.com
    restart: unless-stopped
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.domain1com.tls=true"
      - "traefik.http.routers.domain1com.entrypoints=websecure"
      - "traefik.http.routers.domain1com.rule=Host(`domain1.com`)"
      - "traefik.http.routers.domain1com.tls.certresolver=myresolver"
    environment:
      - PUID=1001
      - PGID=1001
    volumes:
      - domain1.com:/var/www/html

  domain2.com:
    image: wordpress
    container_name: domain2.com
    hostname: domain2.com
    restart: unless-stopped
	labels:
      - "traefik.enable=true"
      - "traefik.http.routers.domain2com.tls=true"
      - "traefik.http.routers.domain2com.entrypoints=websecure"
      - "traefik.http.routers.domain2com.rule=Host(`domain2.com`)"
      - "traefik.http.routers.domain2com.tls.certresolver=myresolver"
    environment:
      - PUID=1001
      - PGID=1001
    volumes:
      - domain2.com:/var/www/html

volumes:
  traefik:
  domain1.com:
  domain2.com:

This is the log output in portainer:

2024-11-14T13:45:06Z INF Traefik version 3.2.0 built on 2024-10-28T14:49:00Z version=3.2.0
2024-11-14T13:45:06Z INF 
Stats collection is disabled.
Help us improve Traefik by turning this feature on :)
More details on: https://doc.traefik.io/traefik/contributing/data-collection/
2024-11-14T13:45:06Z INF Starting provider aggregator aggregator.ProviderAggregator
2024-11-14T13:45:06Z INF Starting provider *traefik.Provider
2024-11-14T13:45:06Z INF Starting provider *acme.ChallengeTLSALPN
2024-11-14T13:45:06Z INF Starting provider *docker.Provider
2024-11-14T13:45:06Z INF Starting provider *acme.Provider
2024-11-14T13:45:06Z INF Testing certificate renew... acmeCA=https://acme-v02.api.letsencrypt.org/directory providerName=myresolver.acme
2024-11-14T13:45:10Z INF Register... providerName=myresolver.acme

When I try to visit either one of the domains, I get a message "404 page not found"

What I'm I doing wrong?

Enable Traefik debug log, enable and check Traefik access log in JSON format (doc) and check Traefik dashboard.

It’s best practice to use explicit Docker networks, also enable http-to-https redirect, see simple Traefik example.

I followed the example and changed it to this

  traefik:
    image: traefik
    container_name: traefik
    hostname: traefik
    restart: unless-stopped
    command:
      - --api.dashboard=true
      - --log.level=DEBUG
      - --accesslog=true
      - --providers.docker.network=root_default
      - --providers.docker.exposedByDefault=false
      - --entrypoints.web.address=:80
      - --entrypoints.web.http.redirections.entrypoint.to=websecure
      - --entryPoints.web.http.redirections.entrypoint.scheme=https
      - --entrypoints.websecure.address=:443
      - --entrypoints.websecure.asDefault=true
      - --entrypoints.websecure.http.tls.certresolver=myresolver
      - --certificatesresolvers.myresolver.acme.email=my@email.net
      - --certificatesresolvers.myresolver.acme.tlschallenge=true
      - --certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json
    environment:
      - PUID=1001
      - PGID=1001
    ports:
      - 80:80
      - 443:443
      - 8080:8080
    volumes:
      - traefik:/letsencrypt
      - /var/run/docker.sock:/var/run/docker.sock

  domain1.com:
    image: wordpress
    container_name: domain1.com
    hostname: domain1.com
    restart: unless-stopped
    labels:
      - traefik.enable=true
      - traefik.http.routers.domain1com.rule=Host(`domain1.com`) || Host(`www.domain1.com`)
      - traefik.http.services.domain1com.loadbalancer.server.port=80
    environment:
      - PUID=1001
      - PGID=1001
    volumes:
      - domain1.com:/var/www/html

There are no errors in the log, and when I visit the domain, the wordpress installer is shown. But for some reason, it's like there's no .css loaded.

I go through the wordpress setup anyway, and the whole website is like missing .css. In the wordpress admin area I notice that wordpress is configured to use http instead of https. Even though on the browser url it shows https. When I change it to https in wordpress and save, I get a message " This page isn’t working right now - ERR_TOO_MANY_REDIRECTS"

That’s WordPress. Everything is always redirected to the URL originally set.

Three options:

  1. Completely re-install, set correct base
  2. Disable Traefik https redirect, change it online. You probably need to use a different browser, as they love to keep and force using https when used once.
  3. Change the settings directly in DB, I think it’s in two places, search for a tutorial.