markhorrocks
markhorrocks

Reputation: 1408

How can I serve Wordpress with Traefik v2.3 behind an AWS ALB with a custom path?

I have a Wordpress blog which I want to host at mydomain.com/blog. I am using Traefik v2.3 in Docker with the image wordpress:latest.

I have an AWS ALB load balancer which terminates certificates on https :443 and sends trafick to http:80. I don't want to terminate the tls certificate in Traefik. Even when I comment out the tls=true and resolver labels from the config I still get an error in my traefik logs.

level=error msg="Unable to obtain ACME certificate for domains "www.mydomain.com": unable to generate a certificate for the domains [www.mydomain.com]: error: one or more domains had a problem:\n[www.mydomain.com] acme: error: 403 :: urn:ietf:params:acme:error:unauthorized :: Cannot negotiate ALPN protocol "acme-tls/1" for tls-alpn-01 challenge, url: \n" providerName=letsencryptresolver.acme routerName=rxblog-secure@docker rule="Host(www.mydomain.com) && PathPrefix(/blog)"

In the browser I get "The page isn't redirecting properly".

Here is my wordpress config:

version: '3.8'

networks:
  traefik:
    external: true

volumes:
  data:

services:

  blog:
    image: wordpress:latest
    container_name: blog
    restart: always
    networks:
      - traefik
    environment:
      - WORDPRESS_DB_HOST=us-east-1.rds.amazonaws.com
      - WORDPRESS_DB_USER=wordpress
      - WORDPRESS_DB_PASSWORD=
      - WORDPRESS_DB_NAME=wordpress
    volumes:
      - type: volume
        source: data
        target: /var/www/html
      - type: bind
        source: ./uploads.ini
        target: /usr/local/etc/php/conf.d/uploads.ini
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.blog.entrypoints=web"
      - "traefik.http.routers.blog.rule=Host(`www.mydomain.com`) && PathPrefix(`/blog`)"
      - "traefik.http.routers.blog.middlewares=redirect-to-https@docker"
      - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
      - "traefik.http.routers.blog-secure.entrypoints=websecure"
      - "traefik.http.routers.blog-secure.rule=Host(`www.mydomain.com`) && PathPrefix(`/blog`)"
      - "traefik.http.services.blog-secure.loadbalancer.server.port=80"
      - "traefik.http.routers.blog-secure.tls=true"
      - "traefik.http.routers.blog-secure.tls.certresolver=letsencryptresolver"
      - "traefik.http.middlewares.blog-secure.stripprefix.prefixes=/blog"
      - "traefik.http.middlewares.blog-secure.stripprefix.forceslash=false"

I edited my labels as follows:

- "traefik.enable=true"
- "traefik.http.routers.rxblog.entrypoints=web"
- "traefik.http.routers.wordpress.rule=Host(`www.mydomain.com`) && PathPrefix(`/`)"
- "traefik.http.services.rxblog.loadbalancer.server.port=80"
- "traefik.http.middlewares.rxblog.stripprefix.prefixes=/blogtest"
- "traefik.http.middlewares.rxblog.stripprefix.forceslash=false"

and I added an .htaccess file like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

I can't get any combinations of the above to work. I just get a 404 for /blog/

Upvotes: 3

Views: 772

Answers (1)

Cyril G.
Cyril G.

Reputation: 2017

Remove tls setting on the router.

- "traefik.http.routers.blog-secure.tls=true"
- "traefik.http.routers.blog-secure.tls.certresolver=letsencryptresolver"

Upvotes: -1

Related Questions