Background
I am working on adding a Dockerized blog stack (Wordpress + MariaDB) to our existing website that runs on Nginx. location /
already serves out the website, and I have been instructed to add logic to the Nginx config where /blog
redirects all traffic to the Docker container.
Attempt 1
- I started the wordpress container at
localhost:9999
on the server. - Using the references I added additional logic:
location ^~ /blog {
proxy_pass http://localhost:9999;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
}
Problem:
Wordpress redirected http://server/blog
to http://wp-admin/install.php
, and since there was no rule for this I got a 404.
Attempt 2
I changed the location
to process /blog
as well as any URL containing wp-.*
. The assumption is that all Wordpress pages will have that URL.
location ~ ^/(blog|wp-.*) {
This worked through the Wordpress setup.
And if I explicitly visit http://server/wp-admin
I am able to go to the blog admin pages.
Problem:
- The Wordpress blog pages do not satisfy the regexes above, and return a 404. e.g.
http://server/?p=31
is a link to a blog post.
Attempt 3
Just for the heck of it I redirected location /
to the Docker container and the blog works perfectly. But that is not the problem statement I have, sadly.
Question
What do I do next, in order to serve all wordpress-specific requests from? I feel I am getting into a loop of fighting regexes when there might be a more elegant solution here.