简体   繁体   English

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

[英]Configuring NGINX with WordPress Multisite installed in a sub-directory

I am attempting to install a WordPress Multisite on an NGINX server. 我正在尝试在NGINX服务器上安装WordPress Multisite。 The multisite is a sub-domain install, and WordPress is installed in its own directory. 多站点是子域安装,而WordPress则安装在其自己的目录中。 Most everything works (front end pages, categories, posts, admin functionality, etc.), but when trying to navigate to the Multisite Network admin ( /wp-admin/network ) I get a 404 error. 大多数功能都能正常工作(前端页面,类别,帖子,管理员功能等),但是当尝试导航到多站点网络管理员( /wp-admin/network )时,出现404错误。 This works if I manually add my subdirectory to the url ( /wp/wp-admin/network ), but it won't automatically redirect. 如果我将子目录手动添加到url( /wp/wp-admin/network ),则此方法有效,但不会自动重定向。 I have tried many different configurations in my NGINX conf file, with no success. 我在NGINX conf文件中尝试了许多不同的配置,但没有成功。 Below is what I have landed on for the conf file as for now. 到目前为止,下面是我为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;
    }
}

I have tried to follow the setup instructions on the NGINX site without success: https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/ 我尝试按照NGINX网站上的设置说明进行操作,但未成功: https ://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/

I also read on the NGINX site that using ifs in the conf file is not a good idea, so I am not sure that the following block is very kosher. 我还在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;
}

Any assistance to resolve this is greatly appreciated. 任何帮助解决此问题的帮助将不胜感激。

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

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

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