简体   繁体   English

nginx 配置,用于在 Wordpress 子域多站点的每个子站点上提供静态内容

[英]nginx configuration for serving static content on each subsite of Wordpress subdomain multisite

The Wordpress multisite(subdomain) is like this: Wordpress 多站点(子域)是这样的:

  • root domain: xxxx.com根域:xxxx.com
  • subsite 1: a.xxxx.com子站点 1:a.xxxx.com
  • subsite 2: b.xxxx.com子站点 2:b.xxxx.com
  • subsite 3: c.xxxx.com子站点 3:c.xxxx.com

I want to add subdirectory(which serve static content) to each subsite, it look like this:我想向每个子站点添加子目录(提供静态内容),它看起来像这样:

  • xxxx.com/z/ xxxx.com/z/
  • a.xxxx.com/z/ a.xxxx.com/z/
  • b.xxxx.com/z/ b.xxxx.com/z/
  • c.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? xxxx.com/z/ 中的静态内容默认正确服务,我只需要创建一个名为 /z/ 的文件夹,并在那里添加内容,但如何让其他子站点下的其他 /z/ 也正确提供内容? is that possible?那可能吗? (the static content is different for each subsite, although they are all named /z/ (每个子站点的静态内容是不同的,虽然它们都被命名为/z/

part of the exiting nginx config file:退出的 nginx 配置文件的一部分:

    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;
    } 

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.仅使用一个服务器定义是不可能实现的,因为资产的内容不同并且/var/www/htdocs下的文件夹也会不同。 You can use the following servers with the rewrite statement to chive your goal (you need to create the a,b,c folders also)您可以使用以下服务器和 rewrite 语句来实现您的目标(您还需要创建 a、b、c 文件夹)

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.如果您只想在一台服务器上执行此操作,则需要更改rewrite语句以依赖于请求的域。 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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM