WordPress via Traefik returns Bad Request for any of PHP scripts

Hello World! :wink:

I start Wordpress container and now trying to get Traefik to be it's reverse proxy, with some success..

% curl -I https://ABC.XYZ.ts.net/wordpress
HTTP/2 301
content-type: text/html; charset=iso-8859-1
date: Sat, 23 Mar 2024 23:28:06 GMT
location: http://ABC.XYZ.ts.net/wordpress/
server: Apache/2.4.57 (Debian)

% curl -I https://ABC.XYZ.ts.net/wordpress/
HTTP/2 200
content-type: text/html; charset=UTF-8
date: Sat, 23 Mar 2024 23:28:08 GMT
link: <https://ABC.XYZ.ts.net/wordpress/index.php?rest_route=/>; rel="https://api.w.org/"
server: Apache/2.4.57 (Debian)
x-powered-by: PHP/8.2.17

% curl -I https://ABC.XYZ.ts.net/wordpress/index.php
HTTP/2 400
content-type: text/html; charset=iso-8859-1
date: Sat, 23 Mar 2024 23:28:15 GMT
server: Apache/2.4.57 (Debian)

%

however as soon as I hit wp-login.php (or even index.php), Traefik returns 400.

wordpress:

# cat docker-compose.yaml
version: '3'
services:
  wordpress:
    image: wordpress:latest
    restart: always
# cat docker-compose.override.yaml
version: '3'
services:
  wordpress:
    env_file:
      - ./.env
    environment:
      - WORDPRESS_DEBUG=1
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik_default"
      - "traefik.http.middlewares.wordpress.replacepathregex.regex=^/wordpress/(.*)"
      - "traefik.http.middlewares.wordpress.replacepathregex.replacement=$$1"
      - "traefik.http.routers.wordpress.entrypoints=websecure"
      - "traefik.http.routers.wordpress.middlewares=wordpress@docker"
      - "traefik.http.routers.wordpress.rule=Host(`ABC.XYZ.ts.net`) && Path(`/wordpress`)"
      - "traefik.http.routers.wordpress.tls.certresolver=myresolver"
    networks:
      - mysql_default
      - traefik_default
    volumes:
      - ./var/www/html:/var/www/html
    working_dir: /var/www/html/wordpress
networks:
  mysql_default:
    name: mysql_default
    external: true
  traefik_default:
    name: traefik_default
    external: true
#

traefik:

# cat docker-compose.yaml
version: '3'
services:
  traefik:
    image: traefik:latest
    container_name: traefik
# cat docker-compose.override.yaml
version: '3'
services:
  traefik:
    container_name: traefik
    command:
      - "--log.level=DEBUG"
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.ssh.address=:2224"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--certificatesresolvers.myresolver.tailscale=true"
      - "--entrypoints.web.http.redirections.entrypoint.to=websecure"
      - "--entrypoints.web.http.redirections.entrypoint.scheme=https"
      - "--ping=true"
    healthcheck:
      test: ["CMD-SHELL","traefik healthcheck --ping"]
      interval: 15s
      timeout: 5s
      retries: 2
    image: traefik:beaufort
    networks:
      - default
    ports:
      - 127.0.0.1:8080:8080
      - 80:80
      - 443:443
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /var/run/tailscale/tailscaled.sock:/var/run/tailscale/tailscaled.sock
networks:
  default:
#

Please advise)
Thanks in advance!

  1. Your first curl indicates you originally installed WordPress on http, it is now redirecting from https to http, which is rather unusual. Note that Wordpress saves the first install location and use that forever, unless you change it in GUI or multiple tables in DB.

  2. You are using Path(), which will only do an exact match, you probably want to use PathPrefix().

  3. You are trying to change the path with middleware, this will usually not work with a GUI web application. The initial page might be loaded, but it will request further content like scripts and images on the target service path (/), so that will not be matched by Traefik anymore (/wordpress).

If you want Wordpress to be available on wordpress, then you should probably install it or configure it to that directory.

haha, i arrived to that myself last night but either way thank you so much), you're right!

thanks again!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.