NGINX serve WordPress from sub-path fails with 404, how to fix?

I’d like host review branches for staging, to test and get feedback before publishing to production. I tried to follow some documentation provided online such as the NGINX recipes ( https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/ ) without success! So, how to fix it?

The pattern for the review branches are /review-xxxxx or /review-xx_x-xxx. As I have setup the Deployment pipeline to trigger publishing to AWS ECS for review-* branches and that’s where I’d like to keep it private for tests and feedback only.

I’ve hard typed /review-ci to avoid having to troubleshoot any regex pattern issues and keep it simple to start with. So, you’ll find the /review-ci path in the NGINX Conf file, so that it’s clear what the goal is.

My NGINX conf file looks like:

server {
listen 80;
server_name httpwordpress.docker.localhost;

# Logs
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

# Default location settings
location / {
index index.html index.htm index.php;
}

location /review-ci {
index index.html index.htm index.php;
try_files $uri $uri/ /review-ci/index.php?$args;
}

# Pass the PHP scripts to FastCGI server
location ~ .php$ {

fastcgi_split_path_info ^(.+.php)(/.+)$;

fastcgi_pass php-fpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
}

}

I have perm links active and I should be able to request foobar.com/review-ci/wp-admin and see the login screen.

When I do curl http://httpwordpress.docker.localhost/review-ci/wp-admin, I get:

404 page not found

I’m also using https://github.com/wp-graphql/wp-graphql, which means that the address http://httpwordpress.docker.localhost/review-ci/graphql should return a data response, but instead, I get 404.

This is a small step before I introduce a regex pattern, as I’d like to deploy the application to AWS ECS. And I noticed straight away that this failed with my original setup which I exposed and requested for help in serverfault ( https://serverfault.com/questions/988035/nginx-location-regex-for-prefixed-paths-failure ).

Does anyone know how to fix this?

Thanks for looking and any feedback or hint is appreciated!

Read more here:: NGINX serve WordPress from sub-path fails with 404, how to fix?

Leave a Reply

Your email address will not be published. Required fields are marked *