before explaining what a multusite is, it’s good to learn the terminology to use, with the first WordPress installation you create the first site, only later you can create a network of sites where the first site is called the primary site while all the others are they will call secondary sites. We hypothesized that I created WordPress from domain.tld https://en.m.wikipedia.org/wiki/Second-level_domain and then create the network here I have the first primary site (with id 1 otherwise there are other unexpected events) at this point WordPress puts you two multisite choices with subdirectories (in reality it does not create a directory but is a unique path) or subdomain example Network -> domain.tld
1) with secondary site subdirectory -> domain.tld/ns1
2) or with secondary site subdomain ns1.domain.com
Example secondary site with id 2 (id 1 for primary site) if different it changes in your id https://ns1.domain.tld/wp-admin/network/site-info.php?id=2 (or https://domain.tld/ns1/wp-admin/network/site-info.php?id=2)
in this scenary the Super adminin (owner who installed and subsequently created the network) will have a .domain.tld cookie and then create a cookie on .ns1.domain.tld in the case of installation with subdomain or on domain.tld with subdirectory, means access you have secondary sites without logging in.
From wordpress 4.5 (without WordPress MU Domain Mapping plugins or other plugins) there is the mapping of secondary domains that reference the mapped path or subdomain
Example with subdirectory domain.tld/ns1 (or subdomain ns1.domain.tld) -> any.domain.com
Even if you log in from any.domain.com you will have problems with the cookie because wordpress is requesting to domain.tld/ns1 (or subdomain ns1.domain.tld).
In the first case you can use this define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST']);
otherwise define('COOKIE_DOMAIN', '');
.
if the primary site and all secondary sites with or without mapping do not have the suffix www. you can dynamically remove these four letters from the variable I provided you and if in the case of domain mapping you cannot set subdomains with domain.tld you can also determine which one is mapped and which is not. Having said that you can also configure your dns for domain.tld and *.domain.tld in the case of mapping ns1.domain.tld will have to point to the mapped domain and with this scenario you don’t need to add other variables to wp-config.php, you have to set DOMAIN_CURRENT_SITE on the primary site (statically not with the variable) I think it serves to identify uniquely to which network it belongs.
Nginx multisite subdirectory
This is the Ningx guide offered by wordpress but you have to rely on the htaccess file (there are different types of versions depending on whether you started with WordPress 3.5 or even earlier).
htaccess
Uploaded File Path #Uploaded File Path
Your first site on a fresh install will put uploaded files in the traditional location of /wp-content/uploads/, however all subsequent sites on your network will be in the /wp-content/uploads/sites/ folder, in their own subfolder based on the site number, designated by the database. These files will be accessible via that URL.
This is a change from Multisite 3.0-3.4.2, where images of subsites were stored in /wp-content/blogs.dir/ and were shown in https://example.com/files/ and https://example.com/sitename/files and so on. If you started with a Multisite install older than 3.5, it is not an error if your images show with the URL of /files/.
I refer you to this discussion to set a default domain (read the whole article is also useful for ssl) if it does not correspond to the wordpress domain redirects to id 1 this case in the case of mismatch).
https://stackoverflow.com/questions/9824328/why-is-nginx-responding-to-any-domain-name
This is an example for per domain and subdomain on ningx (have dense for multisite subdomain), in reality you should exclude the www subdomain if you want to follow the rule I recommended to you.
server {
server_name domain.tld *.domain.tld;
[...]
}