-1

The Wordpress multisite(subdomain) is like this:

  • root domain: xxxx.com
  • subsite 1: a.xxxx.com
  • subsite 2: b.xxxx.com
  • subsite 3: c.xxxx.com

I want to add subdirectory(which serve static content) to each subsite, it look like this:

  • xxxx.com/z/
  • a.xxxx.com/z/
  • b.xxxx.com/z/
  • c.xxxx.com/z/

static cotent in xxxx.com/z/ serve correctly by default, I only need to create a folder named /z/, and add content there, but how can i make other /z/ under other subsite serve content correctly as well? is that possible? (the static content is different for each subsite, although they are all named /z/

part of the exiting nginx config file:

    server {
    access_log   /var/log/nginx/access.log;
    error_log    /var/log/nginx/error.log;
    root /var/www/htdocs;
       server_name xxxx.com *.xxxx.com;

    index index.php index.html index.htm;

    # Redis NGINX CONFIGURATION
    set $skip 0;
    # POST requests and URL with a query string should always go to php
    if ($request_method = POST) {
            set $skip 1;
    }
    if ($query_string != "") {
            set $skip 1;
    } 
Long Lu
  • 1
  • 1

1 Answers1

0

This is not possible to achieve with simply only one server definition because the content of the assets is different and the folders under /var/www/htdocs would be different too. You can use the following servers with the rewrite statement to chive your goal (you need to create the a,b,c folders also)

server {
    access_log   /var/log/nginx/access.log;
    error_log    /var/log/nginx/error.log;
    root /var/www/htdocs;
    server_name a.xxxx.com;

    rewrite ^/z/(.*)$ /a/$1 last;
}

server {
    access_log   /var/log/nginx/access.log;
    error_log    /var/log/nginx/error.log;
    root /var/www/htdocs;
    server_name b.xxxx.com;

    rewrite ^/z/(.*)$ /b/$1 last;
}

server {
    access_log   /var/log/nginx/access.log;
    error_log    /var/log/nginx/error.log;
    root /var/www/htdocs;
    server_name c.xxxx.com;

    rewrite ^/z/(.*)$ /c/$1 last;
}

if you want to do this with only one server, you need to change the rewrite statement to depend on the domain of the request. something like this

server {
    access_log   /var/log/nginx/access.log;
    error_log    /var/log/nginx/error.log;
    root /var/www/htdocs;
    server_name *.xxxx.com xxxx.com;

    rewrite ^/z/(.*)$ /$host/$1 last;
}
Al-waleed Shihadeh
  • 2,697
  • 2
  • 8
  • 22