Custom permalinks not working when WordPress is in a subdirectory (Nginx)

Hi

I have a simple static html site and only want to use WordPress as a blog so I have WordPress installed in a subdirectory at example.local/blog

When I go to example.local/blog I can see the default WordPress page, you know, with the Cactus plant on the table, but if try to load any of the pages, say for instance the default WordPress post, example.local/blog/hello-world/ it doesn’t work it just loads the static index.html that’s sitting in my root. Why?

So the url says;

http://example.local/blog/hello-world/

but it’s showing as;

http://example.local/index.html

I checked the site and address url in both the wp-config and the wp-options table using Sequel Pro. I checked the .htaccess file that sits inside /blog and that seams to be fine too…

Please can anyone help me, I’m willing to pay!

1 Like

I just discovered it works if I use the Plain permalinks setting… strange. Any ideas why this is happening?

I followed this thread (linked below), seams like an issue effecting multi sites too. Strangely, switching from Apache to Nginx makes custom permalinks work. For me on the other hand if I switch to Apache, custom permalinks work, but when I switch back to Nginx they’re broken again. Is there any way to get this working with Nginx? Apache is no good for me.

FIX:
I was able to fix this following a video on YouTube titled " NGINX Fix Wordpress Permalink Error!" I can’t advice anyone else do this so make sure you have a backup, but here’s how I did it with the help of the video.

SSH into the site and cd into /etc/nginx/wordpress (I had to do this on another site and for some reason the path was different /etc/nginx/site.conf)
now run the command ‘nano site.conf’

Now above where you can see the line beginning with “location ~* .(?:jpg|jpeg|gif|png|ico|xml)$ …”

Add:

location /blog {
index index.php index.html index.htm;
try_files $uri $uri/ /blog/index.php?$args;
}

Press ctrl+O (the letter O not zero) to write the file and then ctrl+X to exit.

I restarted the site and custom permalinks worked.