Mapping sites for several multisite networks on a single nginx instance


I have a question about the nginx multisite mappings in the case of multiple multisite networks hosted on a single nginx instance.

It seems to me that there is a potential for conflict, since AFAIK the Nginx map function cannot be embedded within a server vhost configuration, meaning that the mappings are shared amongst various vhost servers.

Let's say I have two subdirectory- or path-based multisite networks,

each with its own map.conf file that I want to use as follows:

map $blogname $blogid {  
    default "";  
    include /srv/web/wpmsnet1/.../nginx-helper/map.conf;  
    include /srv/web/wpmsnet2/.../nginx-helper/map.conf;  

Now, consider both multisite networks have a path-based site with the same name (e.g., '/aaa/'), each of which has a different blog id for its respective network. How does the mapping get resolved properly?

As I see it, a brute-force workaround might be to use different names for the $blogid variable in each site's respective vhost configuration files:

map $blogname $wpmsnet1_blogid {  
    default "";  
    include /srv/web/wpmsnet1/.../nginx-helper/map.conf;  
map $blogname $wpmsnet2_blogid {  
    default "";  
    include /srv/web/wpmsnet2/.../nginx-helper/map.conf;  

However, I think a more elegant solution would be to factor the base multisite blog domain or server name into the map, such that it might be used in this way:

map $_server_name$blogname $blogid {  
    default "";  
    include /srv/web/wpmsnet1/.../nginx-helper/map.conf;  
    include /srv/web/wpmsnet2/.../nginx-helper/map.conf;  

However, this would require that the map.conf files produced by the nginx-helper plugin also include the domain name, as follows:    2 ;    3 ;    2 ;    3 ;  

Likewise, I suppose there would be a problem mapping multisite networks using subdomains or subdomain-mappings onto subdirectory blogs when several networks are hosted on a single nginx instance.

Do you agree that such a problem might exist? Or am I missing something?

If it is a problem, do you suppose the nginx-helper plugin can be extended to construct more disambiguated maps, accordingly (perhaps with an option switch that allows for backwards compatibility)? If so, I'd be happy to assist.

Thanks for your time and consideration.



Situation you have explained is 100% valid. :slight_smile:

When I will be faced with that, I will opt for different $blogid values as you have explained. (e.g. $wpmsnet1_blogid and $wpmsnet2_blogid)

Technically we can modify code to use $server_name$blogname, but I feel its better to NOT handle everything in code as with complexity we will face more issues (and time spent in that may be utilized to solve some other problems)

People (like you) who will run into problems of this complexity will most likely find a solution themselves or might drop here on your post above by googling! :wink:

Thanks for a great post :slight_smile:

By the way, if you like to fork nginx-helper project on Github and add a feature to handle this situation in codes, feel free to do it.

We will surely merge your pull-request. :slight_smile:

Hi Rahul,

Thanks for your reply. I appreciate your argument for not implementing a more general solution in the maintained codebase. As this is a more speculative matter than a real requirement, at present anyway, it’s more important to me to just have my understanding of it confirmed. I’m not sure yet whether I’ll fork the code but I’ll let you know if/when I have something pull-worthy. :wink:

Thanks, …Murray

There is one more non-technical reason though.

In my experience, I have seen separate multisite-setup on same server rarely. A more common use-case is creating multi-network setup on top on multisite whenever some separation between multiple sites is desired.

For example, on this server, we have one physical WordPress multisite which contains multiple networks. A network for rtCamp’s business sites, another network for our blogs,
then one more network for client blogs & sites (mostly mini-CMS sites).

We are using this plugin - to manage multiple-networks in one physical WordPress setup.

Nginx-helper is already capable of handling multi-network and few more complicated things. :slight_smile:

I personally will advise to go with multi-network rather than different multisite setup.

Hi Rahul,

Thanks for the feeback. Yes, I saw that there was support built in for multiple network sites and I can certainly appreciate the motivation for using that approach in a production environment.

However, my main motivation here is rather for development and test environments where I want the capability to build multisite network sites to be deployed into production elsewhere. Consequently, I value the isolation of various multisite network instances (each with its own nginx vhost server), particularly for ease of migration from one environment to another.

I’ve just finished coding the enhancement (just 12 lines) and expect to test it within the next couple of days. If it seems to work well enough, I’ll publish a fork on github and let you know so you can pull and merge it, if you like.

Regards, …Murray


We are also facing tough time to automate moving stuff from dev to production environment. As of now focus is on digging deeper into Git to see how we can use power of its hook in the best way.

By the way, in all cases, we have dev and production setup on different servers (sometimes separation is at virtual-machine level).

I’ve just finished coding the enhancement (just 12 lines) and expect to test it within the next couple of days.

Thanks for update. :slight_smile:

Hi Rahul & Saurabh,

This conversation had shifted to an issue and pull request on the github repo but I've not had a reply to my recent comment on that now-closed issue:

I've also just added a comment to the still-open pull request: but thought I'd add a note here, too, just in case. ;-)

I've been distracted with family matters for the past several months and am now just getting back to the business at hand so please forgive me for not raising this earlier.

I was dismayed to find that the latest nginx-helper plugin on does not contain my changes, nor credit for my contribution. It appears as though my code may have been merged but then overwritten by a subsequent commit.

Please advise as to the disposition of this change request and whether there is anything I can do help it along.

Thanks and take care, ...Murray

@rahul.bansal I suppose I should have used the proper form to mention you. Please respond to my previous comment in this thread. Thanks, ...M