I’m trying to deploy WordPress on a specific path using AWS Application Load Balancer. My ALB has a domain like balancer.mysite.com and I want to run WordPress under the /blog/ path instead of the root directory.
I’m using the official WordPress Docker container and planning to deploy it on ECS. The setup works fine when WordPress runs at https://balancer.mysite.com/ but I can’t get it working properly under https://balancer.mysite.com/blog/.
I’ve tried installing WordPress directly in the subfolder and also tried installing it first at root level, then moving it to /blog/ by updating the WordPress URL settings. Neither approach seems to work correctly.
What’s the right way to configure WordPress to run under a subpath with ALB? Are there specific WordPress configuration changes or ALB listener rules I need to set up? Later I plan to add CloudFront to this setup but for now I just need the basic ALB configuration working.
Had a similar challenge when deploying WordPress behind ALB with subpath routing. The key issue is that WordPress needs to know its base URL configuration before it starts serving requests. You’ll need to set the WP_HOME and WP_SITEURL environment variables in your Docker container to match your target path like WP_HOME=https://balancer.mysite.com/blog and WP_SITEURL=https://balancer.mysite.com/blog. On the ALB side, configure your listener rules to forward requests from /blog/* to your target group, but make sure the health check path is set to /blog/wp-admin/install.php or another valid WordPress endpoint under that path. Also worth noting that you might need to handle the path rewriting correctly - some setups require the ALB to strip the /blog prefix when forwarding to the container, while others keep it intact. Test both approaches to see which works with your WordPress configuration.
WordPress subpath deployment with ALB requires careful handling of both the application configuration and load balancer routing. From my experience with similar setups, the Docker container configuration is crucial - you need to mount a custom wp-config.php file that explicitly defines the WordPress addresses rather than relying solely on environment variables. Set define(‘WP_HOME’,‘https://balancer.mysite.com/blog’) and define(‘WP_SITEURL’,‘https://balancer.mysite.com/blog’) directly in the configuration file. For the ALB configuration, create a listener rule that matches the path pattern /blog/* and forwards to your ECS target group. The tricky part is ensuring your container application actually serves content from the root path internally while WordPress thinks it’s running from /blog/. You may need to configure your web server (Apache/Nginx) within the container to handle this URL rewriting properly. Test the setup thoroughly before adding CloudFront as it adds another layer of complexity with caching and path handling.
been there! the wordpress container itself needs tweaking - modify your dockerfile to copy a custom .htaccess with the right rewrite base rules for /blog/. also check if your alb target group health checks are actually hitting /blog/wp-login.php instead of root. missed that detail on my first attempt and spent hours debugging