Nginx conf file to have Wordpress running in a subfolder

Franck Mercado
1 min readFeb 2, 2019

--

Given that for this example, the server’s setup is for multiple domain names under a single Nginx configuration, what we can do to host a Wordpress site under a sub folder is to have the this site’s nginx conf file located in:

/etc/nginx/sites-available/my-cool-site.conf

And inside, notice the use of the sub folder “my-folder”:

location /my-folder {
try_files $uri $uri/ /my-folder/index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(/my-folder)(/.*)$;
}

And to install Wordpress in the root folder, it would be like this:

location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
}

Also keep in my that Wordpress saves the site’s url of the site in the Admin panel under Settings > General section.

This helped me, not only when setting up a new site, but also when migrating existing Wordpress site from a sub folder to the root path in Nginx under Ubuntu OS.

Useful Link

Nginx + Wordpress: https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/

Happy coding!

--

--

Franck Mercado