使用安装在子目录中的WordPress Multisite配置NGINX

时间:2017-08-07 19:15:40

标签: php wordpress nginx server multisite

我正在尝试在NGINX服务器上安装WordPress Multisite。多站点是子域安装,WordPress安装在自己的目录中。大多数一切正常(前端页面,类别,帖子,管理功能等),但在尝试导航到多站点网络管理员(/wp-admin/network)时,我收到404错误。如果我手动将我的子目录添加到网址(/wp/wp-admin/network),但是它不会自动重定向,则此方法有效。我在NGINX配置文件中尝试了很多不同的配置,没有成功。以下是我现在为conf文件登陆的内容。

upstream php {
        server unix:/var/run/php/php7.0-fpm.sock;
        server 127.0.0.1:9000;
}

map $http_host $blogid {
    default -999;

    #Ref: http://wordpress.org/extend/plugins/nginx-helper/
    include /var/www/vhosts/test.example.com/public/wp-content/uploads/nginx-helper/map.conf ;
}

# Default server configuration
#
server {
    listen 80;
    listen [::]:80;

    server_name test.example.com *.test.example.com;
    server_name_in_redirect off;

    root /var/www/vhosts/test.example.com/public;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html;

    if (!-e $request_filename) {
                rewrite /wp-admin$ $scheme://$host$uri/ permanent;         
                rewrite ^/wp(/[^/]+)?(/wp-.*) /wp$2 last;      
                rewrite ^/wp(/[^/]+)?(/.*\.php)$ /wp$2 last;
        }

    location = /favicon.ico {
                log_not_found off;
                access_log off;
        }

    location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }

    location /wp-admin {
        rewrite ^/wp-admin$ /wp/wp-admin/ redirect;
    }

    location / {
        # This is cool because no php is touched for static content.
                # include the "?$args" part so non-default permalinks doesn't break when using query string
                try_files $uri $uri/ /wp/index.php?$args;
    }

    location /wp {
        # This is cool because no php is touched for static content.
                # include the "?$args" part so non-default permalinks doesn't break when using query string
                try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        try_files $uri /wp/index.php;
        #fastcgi_split_path_info ^(/wp)(/.*)$;
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                include fastcgi.conf;
                fastcgi_intercept_errors on;
                fastcgi_pass php;
        }

    #WPMU Files
        location ~ ^/files/(.*)$ {
                try_files /wp/wp-content/blogs.dir/$blogid/$uri /wp/wp-includes/ms-files.php?file=$1 ;
                access_log off; log_not_found off;      expires max;
        }

        #WPMU x-sendfile to avoid php readfile()
    location ^~ /blogs.dir {
            internal;
            alias /var/www/test.example.com/public/wp-content/blogs.dir;
            access_log off;     log_not_found off;      expires max;
    }

    location ~* ^.+.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
        access_log off; log_not_found off; expires max;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    location ~ /\.ht {
        deny all;
    }
}

我尝试按照NGINX网站上的设置说明进行操作但未成功:Using nuxt.js programmatically

我还在NGINX网站上读到,在conf文件中使用ifs并不是一个好主意,所以我不确定下面的块是非常犹太的。

if (!-e $request_filename) {
    rewrite /wp-admin$ $scheme://$host$uri/ permanent;         
    rewrite ^/wp(/[^/]+)?(/wp-.*) /wp$2 last;      
    rewrite ^/wp(/[^/]+)?(/.*\.php)$ /wp$2 last;
}

非常感谢您解决此问题的任何帮助。

1 个答案:

答案 0 :(得分:0)

基于此评论:https://wordpress.stackexchange.com/a/156420/125559,听起来此配置不适用于WordPress Multisite。