How to uese WordPress multisite with NGINX

NGINX multisite  Setup for WordPress

WordPress multisites (also referred to as network sites) allow you to run multiple websites from the one codebase. This can reduce the management burden of having separate WordPress installations when you have similar sites. For example, if you have a sporting site with separate news and staff for different regions, you can use a multisite installation to accomplish this.

Table of contents[Show]

To convert a WordPress site into a multisite, you need to add the configuration variable into your config file wp-config.php:

define( 'WP_ALLOW_MULTISITE', true ); 

Under the Tools menu, you'll now see an extra menu called Network Setup. This will present you with two main options, Sub-domains and Sub-directories. These are the two different ways the multisite installation will work. The Sub-domains option has the sites separated by domain names, for example, and The Sub-directories option means that the sites are separated by directories, for example, and

There's no functional difference between the two, it's simply an aesthetic choice. However, once you've made your choice, you cannot return to the previous state.

Once you've made the choice, it will then provide the additional code to add to your wp-config.php file.

Here's the code for my example, which is subdirectory based:

define('MULTISITE', true); 
define('SUBDOMAIN_INSTALL', false); 
define('DOMAIN_CURRENT_SITE', ''); 
define('PATH_CURRENT_SITE', '/'); 
define('SITE_ID_CURRENT_SITE', 1); 
define('BLOG_ID_CURRENT_SITE', 1); 

Because NGINX doesn't support .htaccess files, the second part of the WordPress instructions will not work. Instead, we need to modify the NGINX configuration to provide the rewrite rules ourselves.

In the existing /etc/nginx/conf.d/wordpress.conf file, you'll need to add the following just after the location / directive:

if (!-e $request_filename) { 
    rewrite /wp-admin$ $scheme://$host$uri/ permanent; 
    rewrite ^(/[^/]+)?(/wp-.*) $2 last;                      
    rewrite ^(/[^/]+)?(/.*\.php) $2 last;                    

Although the if statements are normally avoided if possible, in this instance, it will ensure the subdirectory multisite configuration works as expected. If you're expecting a few thousand concurrent users on your site, then it may be worthwhile investigating the static mapping of each site. There are plugins to assist with the map generations for this, but they are still more complex compared to the if statement.

If you've selected subdomains, your code to put in wp-config.php will look like this:

define('MULTISITE', true); 
define('SUBDOMAIN_INSTALL', true); 
define('DOMAIN_CURRENT_SITE', ''); 
define('PATH_CURRENT_SITE', '/'); 
define('SITE_ID_CURRENT_SITE', 1); 
define('BLOG_ID_CURRENT_SITE', 1); 

You'll also need to modify the NGINX config as well to add in the wildcard for the server name:

server_name  *; 

You can now add in the additional sites, such as, and there won't be any changes required for NGINX.

Вас заинтересует / Intresting for you:

Configuring NGINX for WordPres...
Configuring NGINX for WordPres... 419 views Гвен Sun, 20 Mar 2022, 07:01:55
WordPress optimization: minimu...
WordPress optimization: minimu... 2786 views Fortan Wed, 13 Nov 2019, 12:45:25
The Future of WordPress: how p...
The Future of WordPress: how p... 348 views dbstalker Mon, 31 Jan 2022, 17:11:40
Optimizing WordPress for SEO
Optimizing WordPress for SEO 3113 views Fortan Wed, 13 Nov 2019, 11:25:09
Comments (0)
There are no comments posted here yet
Leave your comments
Posting as Guest
Suggested Locations