0

I just created a subdirectory multisite install, and have a problem: When I visit my sub-sites, they automaticly redirect, 302, to the homepage of the main site. For example, if I visit 2mb.solutions/michaeltaboada, it will redirect, 302, to 2mb.solutions. I also have some domains mapped to my subsites, and if I visit michaeltaboada.me, it will also redirect to 2mb.solutions. I am using nginx 1.11.5 and WordPress 4.6.1. My nginx config is below:

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

Any idea why the sites would be automatically redirecting? One other thing to note is that if I visit 2mb.solutions/michaeltaboada/wp-admin, it lets me log in. However, if I visit michaeltaboada.me/wp-admin, it redirects to the main site. -Michael.

1 Answer 1

0

Turns out my domain mapping plugin was to blame. It didn't like when I linked (ln -s) the sunrise.php file to my wp-content folder, I actually needed to copy (cp) it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.