Containerized WordPress from Sub-directory with Traefik

It becomes so easy to host a WordPress CMS using its official Docker container image. If only 1 domain is available, it might be useful to serve WordPress from subdirectory, i.e https://$SITE_URL/blog/.

· 2 min read
Containerized WordPress from Sub-directory with Traefik

It becomes so easy to host a WordPress CMS using its official Docker container image. If only 1 domain is available, it might be useful to serve WordPress from subdirectory, i.e https://$SITE_URL/blog/.

First, follow the official documentation (Method II) to setup WordPress installation in subdirectory.

Giving WordPress Its Own Directory
Many people want WordPress to power their website’s root (e.g. but they don’t want all of the WordPress files cluttering up their root directory. WordPress allows you to install it into…
Use Method II (With URL Changes) to finish the installation
$ export SUBPATH="blog"
$ mv !($SUBPATH) $SUBPATH/
$ cp SUBPATH/index.php index.php
$ sed -i "s/wp-blog-header.php/$SUBPATH\/wp-blog-header.php/g"

Then configure Traefik label:

version: '3'
services:
	wordpress:
    	....
        labels:
            - 'traefik.enable=true'
            - 'traefik.http.routers.blog.rule=Host(`$SITE_URL`) && PathPrefix(`/blog`)'
            - 'traefik.http.routers.blog.entrypoints=https'
        ....
        
            - 'traefik.http.routers.blog.tls=true'

References

Subdirectory problem (wp-admin redirect) · Issue #388 · docker-library/wordpress
I have looked through several related issues, but could not find a solution. It only happens when I'm at /wp-admin. I get a sort of 'redirect' when I access wp-admin. Seems like a pushS...
[URGENT NEED] [Please Help Needed A Lot] - Unable to route nginx to wordpress (fpm or apache) for /subdirectory config · Issue #221 · docker-library/wordpress
I have been trying this more than 12 hours and still not able to figure the perfect nginx config to route to a /blog wordpress installation. Need this in real urgent basis, have to shift company&#3...