WordPress In a Sub Directory Settings for Ubuntu Nginx is Simple
Every time I have to install a WordPress in a sub folder, I suffer from trying to search the correct Nginx settings online. Even though the wordpress.org has provided the so complicated Nginx settings that doesn’t ends up solving the problem.
I have tried Stack overflow, expert exchange user proposed solution and none of them works. Eventually I figured out that the solution is very simple.
I am using Ubuntu 16.04 with Nginx. My wordpress was installed in a /blog directory. I think the latest wordpress is become way more intelligent compare with many years ago. Everything seems fine to install a wordpress into a sub directory on Ubuntu Ngnix.
The only issue is when you want to enable the URL rewrite at the permalink options, the slug will return 404:
The Solution is Simple
You don’t need to create a separated server block
server { ... }
Just add the below settings into your root server block:
location /blog { root /var/www/example.com/html; index index.php; try_files $uri $uri/ /blog/index.php?$args; }
/blog is your sub directory where your wordpress was installed.
/var/www/example.com/html is the path to your root directory.
You are good after adding these few lines and the slug and URL rewrite will just work.