"Error 502: Bad Gateway" When setting up my Wordpress Docker containers with Traefik as reverse proxy?

Howdy, if anyone is here.

So basically, I'm trying to setup a WordPress site through Docker compose but its returning "Error 502: Bad Gateway",

I checked the error logs of the WordPress docker container and it says

:
"AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.22.0.3. Set the 'ServerName' directive globally to suppress this message"

To solve the error I've tried adding the ServerName to the domain that I have:

nano /etc/apache2/sites-available/000-default.conf

ServerName wordpress.domain.com

--

But after restarting the containers, it still returned Bad Gateway.


Here's my :

compose.traefik.yaml

services:
  wordpress:
    labels:
      - "traefik.docker.network=traefik-public"
      - "traefik.enable=true"
      - "traefik.http.routers.wordpress-http.entrypoints=http"
      - "traefik.http.routers.wordpress-http.middlewares=https-redirect"
      - "traefik.http.routers.wordpress-http.rule=Host(`wordpress.domain.com`)"
      - "traefik.http.routers.wordpress-https.rule=Host(`wordpress.domain.com`)"
      - "traefik.http.routers.wordpress.service=wordpress"
      - "traefik.http.routers.wordpress-https.entrypoints=https"
      - "traefik.http.routers.wordpress-https.service=wordpress"
      - "traefik.http.routers.wordpress-https.tls=true"
      - "traefik.http.routers.wordpress-https.tls.certresolver=le"
      - "traefik.http.services.wordpress.loadbalancer.server.port=8000"
      - "traefik.http.routers.wordpress.tls=true"
    networks:
      - traefik-public

networks:
  traefik-public:
    external: true

docker-compose.yaml

#version: '3'

networks:
  wordpress-network:
    external: true
  traefik-public:
    external: true
services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: myrootpass
      MYSQL_DATABASE: wordpress_db
      MYSQL_USER: wordpress_admin
      MYSQL_PASSWORD: myrootpass
    networks:
      - wordpress-network
  wordpress:
    depends_on:
      - db
    image: wordpress:latest
    ports:
      - 8000:80
    restart: always
    volumes:
      - wp_data:/var/www/html
    networks:
      - wordpress-network
      - traefik-public
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress_admin
      WORDPRESS_DB_PASSWORD: myrootpass
volumes:
  db_data: {}
  wp_data: {}

I use the following command to run the containers:

$docker compose
--project-name wordpress
-f ~/apps/wordpress/docker-compose.yaml
-f ~/apps/wordpress/compose.traefik.yaml
up -d

Set docker.network (doc).

1 Like