I have a dev server where I upload client websites, every WordPress site has its own DB and directory (every site is independent). I have one server block. My problem is with the pretty permalinks, this works for me:
server_name dev.example.tld;
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
location / {
try_files $uri $uri/ =404;
add_header 'Cache-Control' 'no-store, no-cache, must-revalidate, proxy-revalidate, max-$
expires off;
}
location /site_1/ {
index index.php;
try_files $uri $uri/ /site_1/index.php?$args;
}
location /site_2/ {
index index.php;
try_files $uri $uri/ /site_2/index.php?$args;
}
I've been searching for a way to do it one time instead of adding the location block for each site but no luck.
You could change the
location
into a regular expression and capture the site name:Alternatively, accomplish the same effect by using a rewrite: