WordPress多站点安装302的所有子站点重定向到主站点

时间:2016-11-19 作者:Michael Taboada

我刚刚创建了一个子目录multisite install,但遇到了一个问题:当我访问我的子站点时,它们会自动将302重定向到主站点的主页。例如,如果我访问2mb。解决方案/michaeltaboada,它将重定向302到2mb。解决方案。我也有一些域映射到我的子网站,如果我访问michaeltaboada。我,它也会重定向到2mb。解决方案。我正在使用nginx 1.11.5和WordPress 4.6.1。我的nginx配置如下:

server {
    listen 80;
    listen [::]:80;
    server_name 2mb.solutions www.2mb.solutions michaeltaboada.me www.michaeltaboada.me 3dm.audio www.3dm.audio 2mb.info www.2mb.info 2mb.review www.2mb.review getyourphix.tk www.getyourphix.tk eldritchfiction.net www.eldritchfiction.net lolmud.net www.lolmud.net;
    return 301 https://$host$request_uri;
}
#map $http_host $blogid {
    # default 0;
    # 2mb.solutions 1;
    #www.2mb.solutions 1;
    #michaeltaboada.me  2;
    #www.michaeltaboada.me 2;
    # 3dm.audio 9;
    #www.3dm.audio 9;
    #2mb.info 4;
    #www.2mb.info 4;
    #2mb.review 5;
    #www.2mb.review 5;
    #getyourphix.tk 6;
    #www.getyourphix.tk 6;
    #eldritchfiction.net 7;
    #www.eldritchfiction.net 7;
    #lolmud.net 8;
    #www.lolmud.net 8;
#}
map $uri $blogname{
    ~^(?P<blogpath>/[^/]+/)files/(.*)       $blogpath ;
}

map $blogname $blogid{
    /michaeltaboada/ 2;
    /3dm/ 9;
    /2mb-info/ 4;
    /2mb-review/ 5;
    /getyourphix/ 6;
    /eldritchfiction/ 7;
    /lolmud/ 8;
        getyourphix.tk  6;
        3dm.audio   9;
        eldritchfiction.net 7;
        michaeltaboada.me   2;
        2mb.review  5;
        2mb.info    4;
        lolmud.net  8;
}

server {
    access_log off;
    error_log /etc/nginx/logs/error.log;
    server_name 2mb.solutions www.2mb.solutions michaeltaboada.me www.michaeltaboada.me 3dm.audio www.3dm.audio 2mb.info www.2mb.info 2mb.review www.2mb.review getyourphix.tk www.getyourphix.tk eldritchfiction.net www.eldritchfiction.net lolmud.net www.lolmud.net;
    root /storage/websites/2mb.solutions/public_html;
    listen 443 ssl;
    listen [::]:443 ssl;
    index index.php;
    server_name_in_redirect off;
        ssl_certificate /etc/letsencrypt/live/2mb.review/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/2mb.review/privkey.pem;
        ssl_client_certificate /etc/nginx/cloudflare.pem;
        ssl_verify_client on;

        etag on;
        expires 7d;
        if_modified_since before;

        gzip on;
        gzip_vary on;
        gzip_comp_level 6;
        gzip_types text/plain text/xml image/svg+xml # text/html in core already.
            application/rss+xml application/atom+xml application/xhtml+xml
            text/css application/json application/x-javascript
            application/font-otf application/font-ttf;


        location ~* \\.(?:ttf|ttc|otf|eot|woff|woff2|css|js)$ {
            add_header Access-Control-Allow-Origin *;
        }

        # ? This is optional, but suggested. It\'s a flag to tell Comet Cache
        # that you completed this Nginx configuration.


    add_header X-SNOOPER "Do you like breaking php code? Then contact 2MB and apply to be a beta tester! Visit https://2mb.solutions and mention this header! Oh and yes, we totally stole this idea from wordpress.com. Hats off to ya guys!";

    set $no_cache 0;
        if ($request_method = POST) {
            set $no_cache 1;
        }
        if ($query_string != "") {
            set $no_cache 1;
        }
        if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") {
            set $no_cache 1;
       }
       if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in") {
            set $no_cache 1;
       }

    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    location ~* \\.(jpg|png|gif|jpeg|css|js|mp3|wav|swf|mov|doc|pdf|xls|ppt|docx|pptx|xlsx|woff)$ {
                            expires 864000;
    }
    location ~ ^(/[^/]+/)?files/(.+) {
        try_files /wp-content/blogs.dir/$blogid/files/$2 /wp-includes/ms-files.php?file=$2 ;
        access_log off;     log_not_found off; expires max;
    }

    #avoid php readfile()
    location ^~ /blogs.dir {
        internal;
        alias /storage/websites/2mb.solutions/public_html/wp-content/blogs.dir ;
        access_log off;     log_not_found off; expires max;
    }

    if (!-e $request_filename) {
        rewrite /wp-admin$ $scheme://$host$uri/ permanent;
        rewrite ^(/[^/]+)?(/wp-.*) $2 last;
        rewrite ^(/[^/]+)?(/.*\\.php) $2 last;
    }
    ## WP Defender - Prevent information disclosure ##
                    # Turn off directory indexing
    autoindex off;

    # Deny access to wp-config.php file
    location = /wp-config.php {
      deny all;
    }

    # Deny access to revealing or potentially dangerous files in the /wp-content/ directory (including sub-folders)
    location ~* ^/wp-content/.*\\.(txt|md|exe|sh|bak|inc|pot|po|mo|log|sql)$ {
      deny all;
    }
    ## WP Defender - End ##
    ## WP Defender - Prevent PHP Execution ##
    # Stop php access except to needed files in wp-includes
    location ~* ^/wp-includes/.*(?<!(js/tinymce/wp-tinymce))\\.php$ {
      internal; #internal allows ms-files.php rewrite in multisite to work
    }

    # Specifically locks down upload directories in case full wp-content rule below is skipped
    location ~* /(?:uploads|files)/.*\\.php$ {
      deny all;
    }

    #allow access to wordfence php files
    location ~ ^/wp-content/plugins/wordfence/.*\\.php$ {
    include /etc/nginx/fastcgi_params;
        fastcgi_split_path_info ^(.+\\.php)(/.*)$;
    if (!-f $document_root$fastcgi_script_name) {
        return 404;
    }
    # fastcgi_pass unix:/run/php-fpm/php-fpm.sock; 
    fastcgi_pass 127.0.0.1:9000;
    #fastcgi_pass unix:/var/run/hhvm/hhvm.sock;
    fastcgi_index index.php;
    # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param QUERY_STRING    $query_string;
        # include fastcgi_params; 
        fastcgi_intercept_errors on;
        fastcgi_ignore_client_abort off;
        fastcgi_connect_timeout 10;
        fastcgi_send_timeout 10;
        fastcgi_read_timeout 30;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
        fastcgi_cache_bypass $no_cache;
        fastcgi_no_cache $no_cache;
        # fastcgi_cache   CZONE;
        fastcgi_cache_valid   200 302  1h;
        fastcgi_cache_valid   301 1h;
        fastcgi_cache_valid   any 1h;
        fastcgi_cache_min_uses  2;
    }

    # Deny direct access to .php files in the /wp-content/ directory (including sub-folders).
    #  Note this can break some poorly coded plugins/themes, replace the plugin or remove this block if it causes trouble
    location ~* ^/wp-content/.*\\.php$ {
      deny all;
    }
    ## WP Defender - End ##
    location ~ [^/]\\.php(/|$) {
        include /etc/nginx/fastcgi_params;
            fastcgi_split_path_info ^(.+\\.php)(/.*)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }
        # fastcgi_pass unix:/run/php-fpm/php-fpm.sock; 
        fastcgi_pass 127.0.0.1:9000;
        #fastcgi_pass unix:/var/run/hhvm/hhvm.sock;
              fastcgi_param WP_NGINX_CONFIG done;
        fastcgi_index index.php;
        # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param QUERY_STRING    $query_string;
            # include fastcgi_params; 
            fastcgi_intercept_errors on;
            fastcgi_ignore_client_abort off;
            fastcgi_connect_timeout 10;
            fastcgi_send_timeout 10;
            fastcgi_read_timeout 30;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 4 256k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;
            fastcgi_cache_bypass $no_cache;
            fastcgi_no_cache $no_cache;
            # fastcgi_cache   CZONE;
            fastcgi_cache_valid   200 302  1h;
            fastcgi_cache_valid   301 1h;
            fastcgi_cache_valid   any 1h;
            fastcgi_cache_min_uses  2;

    } 
    # No access to .htaccess files.
    location ~ /\\.ht {
        deny  all;
    }
}
你知道为什么网站会自动重定向吗?另一件需要注意的事情是,如果我访问2mb。解决方案/michaeltaboada/wp管理员,它让我可以登录。然而,如果我拜访michaeltaboada。me/wp管理员,它重定向到主站点-迈克尔。

1 个回复
SO网友:Michael Taboada

原来是我的域映射插件造成的。我不喜欢把日出联系起来。php文件到我的wp内容文件夹,我实际上需要复制(cp)它。

相关推荐

WordPress(在HAProxy和Jetty之后),而不是MultiSite,在子文件夹中-并且/en/wp-admin/保持重定向到/wp-admin/

我正在使用一种不同寻常的设置在CentOS 8 Linux上托管3个Wordpress安装。在前面我有HAProxy(卸载TLS),然后我有Jetty configured for FastCGI php fpm和Wordpress。我正在使用Wordpress编写一个用Pixi编写的文字游戏。js。几年来,我一直在使用3个不同的IP地址和3个不同的域名作为我游戏的3种语言版本:en、de、ru。然而,我的文字游戏并不成功,因此我决定放弃额外的域名和IP地址,只使用文件夹为我的游戏服务:wordsbyfa