Want to subscribe to topics you're interested in?
Become a Member

Wordpress Cache-Enabler Plugin Strange Redirection For Wordpress Multi-site Nginx configuration

Discussion in 'Blogs & CMS usage' started by KlueMaster, Aug 14, 2020.

  1. KlueMaster

    KlueMaster Member

    53
    10
    8
    Aug 5, 2017
    Ratings:
    +20
    Local Time:
    6:01 PM
    MariaDB 10
    Hi,

    I made a new WordPress setup on the server, that already has an existing multi-site network (under a different domain). Everything was working fine until I had to make the new one multi-site as well.

    After converting the site to multi-site, and modifying the nginx domain config file (*.ssl.conf) for multi-site, the domain is getting redirected to the previous domain as a child. Specifically, when I'm trying to go to newdomain.com it redirects to newdomaincom.olddomain.com

    I'm not able to figure out the issue. Both domains use .ssl.conf similar to the one below:
    Code (Text):
    #x# HTTPS-DEFAULT
    #server {
    #
    #   server_name newdomain.com www.newdomain.com;
    #   return 302 https://newdomain.com$request_uri;
    #   include /usr/local/nginx/conf/staticfiles.conf;
    # }
    
    map $uri $blogname{
      ~^(?<blogpath>/[^/]+/)sites/(.*) $blogpath ;
    }
    map $blogname $blogid{
      default -999;
      include /home/nginx/domains/newdomain.com/public/wp-content/uploads/nginx-helper/map.conf;
    }
    
    server {
      listen 443 ssl http2;
      server_name newdomain.com www.newdomain.com;
    
      include /usr/local/nginx/conf/ssl/newdomain.com/newdomain.com.crt.key.conf;
      include /usr/local/nginx/conf/ssl_include.conf;
    
      # cloudflare authenticated origin pull cert community.centminmod.com/threads/13847/
      #ssl_client_certificate /usr/local/nginx/conf/ssl/cloudflare/newdomain.com/origin.crt;
      #ssl_verify_client on;
      http2_max_field_size 16k;
      http2_max_header_size 32k;
      http2_max_requests 50000;
      # mozilla recommended
      ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS;
      ssl_prefer_server_ciphers   on;
      #add_header Alternate-Protocol  443:npn-spdy/3;
    
      # before enabling HSTS line below read centminmod.com/nginx_domain_dns_setup.html#hsts
      #add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
      #add_header X-Frame-Options SAMEORIGIN;
      add_header X-Xss-Protection "1; mode=block" always;
      add_header X-Content-Type-Options "nosniff" always;
      #add_header Referrer-Policy "strict-origin-when-cross-origin";
      #add_header Feature-Policy "accelerometer 'none'; camera 'none'; geolocation 'none'; gyroscope 'none'; magnetometer 'none'; microphone 'none'; payment 'none'; usb 'none'";
      #spdy_headers_comp 5;
      ssl_buffer_size 1369;
      ssl_session_tickets on;
    
      # enable ocsp stapling
      resolver 8.8.8.8 8.8.4.4 1.1.1.1 1.0.0.1 valid=10m;
      resolver_timeout 10s;
      ssl_stapling on;
      ssl_stapling_verify on;
    
      # ngx_pagespeed & ngx_pagespeed handler
      #include /usr/local/nginx/conf/pagespeed.conf;
      #include /usr/local/nginx/conf/pagespeedhandler.conf;
      #include /usr/local/nginx/conf/pagespeedstatslog.conf;
    
      # limit_conn limit_per_ip 16;
      # ssi  on;
    
      access_log /home/nginx/domains/newdomain.com/log/access.log combined buffer=256k flush=5m;
      error_log /home/nginx/domains/newdomain.com/log/error.log;
    
      include /usr/local/nginx/conf/autoprotect/newdomain.com/autoprotect-newdomain.com.conf;
      root /home/nginx/domains/newdomain.com/public;
    
      # uncomment cloudflare.conf include if using cloudflare for
      # server and/or vhost site
      include /usr/local/nginx/conf/cloudflare.conf;
      include /usr/local/nginx/conf/503include-main.conf;
    
      #include /usr/local/nginx/conf/wpincludes/newdomain.com/wpcacheenabler_newdomain.com.conf;
      #include /usr/local/nginx/conf/wpincludes/newdomain.com/wpsupercache_newdomain.com.conf;
      include /usr/local/nginx/conf/wpincludes/newdomain.com/rediscache_newdomain.com.conf;
    
      location / {
        include /usr/local/nginx/conf/503include-only.conf;
    
        # Enables directory listings when index file not found
        #autoindex  on;
    
        # for wordpress super cache plugin
        #try_files /wp-content/cache/supercache/$http_host/$cache_uri/index.html $uri $uri/ /index.php?q=$uri&$args;
    
        # for wp cache enabler plugin
        #try_files $cache_enabler_uri $uri $uri/ $custom_subdir/index.php?$args;
    
        # Wordpress Permalinks
        #try_files $uri $uri/ /index.php?q=$uri&$args;
    
        # Nginx level redis Wordpress
        if ($request_uri !~ "^/.+$") {
          return 301 https://$host/home;
        }
    
        try_files $uri $uri/ /index.php?$args;
      }
    
      location ~* /(wp-login\.php) {
        limit_req zone=xwplogin burst=1 nodelay;
        #limit_conn xwpconlimit 30;
        #auth_basic "Private";
        #auth_basic_user_file /home/nginx/domains/newdomain.com/htpasswd_wplogin;
        #include /usr/local/nginx/conf/php-wpsc.conf;
    
        include /usr/local/nginx/conf/php-rediscache.conf;
      }
    
      location ~* /(xmlrpc\.php) {
        limit_req zone=xwprpc burst=45 nodelay;
        #limit_conn xwpconlimit 30;
        #include /usr/local/nginx/conf/php-wpsc.conf;
    
        include /usr/local/nginx/conf/php-rediscache.conf;
      }
    
      location ~* /wp-admin/(load-scripts\.php) {
        limit_req zone=xwprpc burst=5 nodelay;
        #limit_conn xwpconlimit 30;
        #include /usr/local/nginx/conf/php-wpsc.conf;
    
        include /usr/local/nginx/conf/php-rediscache.conf;
      }
    
      location ~* /wp-admin/(load-styles\.php) {
        limit_req zone=xwprpc burst=5 nodelay;
        #limit_conn xwpconlimit 30;
        #include /usr/local/nginx/conf/php-wpsc.conf;
    
        include /usr/local/nginx/conf/php-rediscache.conf;
      }
    
      location ~* /wp-admin/(load-styles\.php) {
        limit_req zone=xwprpc burst=5 nodelay;
        #limit_conn xwpconlimit 30;
        #include /usr/local/nginx/conf/php-wpsc.conf;
    
        include /usr/local/nginx/conf/php-rediscache.conf;
      }
    
      rewrite /files/$ /index.php last;
      if ($uri !~ wp-content/plugins) {
        rewrite /files/(.+)$ /wp-includes/ms-files.php?file=$1 last;
      }
      # Rewrite multisite '.../wp-.' and '.../.php'.
      if (!-e $request_filename) {
        rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
        rewrite ^/[_0-9a-zA-Z-]+.(/wp-admin/.\.php)$ $1 last;
        rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
      }
    
      include /usr/local/nginx/conf/wpincludes/newdomain.com/wpsecure_newdomain.com.conf;
      #include /usr/local/nginx/conf/php-wpsc.conf;
    
      include /usr/local/nginx/conf/php-rediscache.conf;
      include /usr/local/nginx/conf/pre-staticfiles-local-newdomain.com.conf;
      include /usr/local/nginx/conf/pre-staticfiles-global.conf;
      include /usr/local/nginx/conf/staticfiles.conf;
      include /usr/local/nginx/conf/drop.conf;
      #include /usr/local/nginx/conf/errorpage.conf;
      include /usr/local/nginx/conf/vts_server.conf;
    }
    


    Could someone help with this?

    Thanks!
     
    Last edited: Aug 14, 2020
  2. eva2000

    eva2000 Administrator Staff Member

    45,201
    10,280
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,934
    Local Time:
    10:31 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    Not related to your issue but for cleanly posted code, you might want to edit/repost the vhost code in native CODE tags first as it was parsed by forum software for link/domains. For posting code or output from commands to keep the formatting, you might want to use CODE tags for code How to use forum BBCODE code tags :)

    Is newdomaincom.olddomain.com a valid expected domain name ? If so what's output for all these curl header checks (wrap in CODE tags or CODEB tags)
    Code (Text):
    curl -Ik https://newdomaincom.olddomain.com
    

    Code (Text):
    curl -Ik https://newdomain.com
    

    Code (Text):
    curl -Ik https://olddomain.com
    

    Code (Text):
    curl -Ik https://www.newdomain.com
    

    Code (Text):
    curl -Ik https://www.olddomain.com
    
     
  3. KlueMaster

    KlueMaster Member

    53
    10
    8
    Aug 5, 2017
    Ratings:
    +20
    Local Time:
    6:01 PM
    MariaDB 10
    Thanks!

    Actually I had use the wrong code (BCODE) instead of (CODEB), but corrected it soon afterwards. I didn't realize that the links have been converted though.

    Here is the output for all the commands:
    Code (Text):
    curl -Ik https://newdomaincom.olddomain.com
    HTTP/2 302 
    date: Fri, 14 Aug 2020 09:00:14 GMT
    content-type: text/html; charset=UTF-8
    location: https://olddomain.com/wp-signup.php?new=newdomaincom
    server: nginx centminmod
    x-powered-by: centminmod
    x-cache: MISS
    x-cache-2: BYPASS
    x-xss-protection: 1; mode=block
    x-content-type-options: nosniff
    
    curl -Ik https://newdomain.com
    HTTP/2 302 
    date: Fri, 14 Aug 2020 09:00:37 GMT
    content-type: text/html; charset=UTF-8
    location: https://olddomain.com/wp-signup.php?new=newdomain.com
    server: nginx centminmod
    x-powered-by: centminmod
    x-cache: MISS
    x-cache-2: BYPASS
    x-xss-protection: 1; mode=block
    x-content-type-options: nosniff
    
    curl -Ik https://olddomain.com
    HTTP/2 301 
    date: Fri, 14 Aug 2020 09:00:55 GMT
    content-type: text/html
    content-length: 162
    location: https://olddomain.com/home
    server: nginx centminmod
    x-powered-by: centminmod
    x-xss-protection: 1; mode=block
    x-content-type-options: nosniff
    
    curl -Ik https://www.newdomain.com
    HTTP/2 302 
    date: Fri, 14 Aug 2020 09:01:08 GMT
    content-type: text/html; charset=UTF-8
    location: https://olddomain.com/wp-signup.php?new=www.newdomain.com
    server: nginx centminmod
    x-powered-by: centminmod
    x-cache: MISS
    x-cache-2: BYPASS
    x-xss-protection: 1; mode=block
    x-content-type-options: nosniff
    
    curl -Ik https://www.olddomain.com
    HTTP/2 301 
    date: Fri, 14 Aug 2020 09:01:21 GMT
    content-type: text/html
    content-length: 162
    location: https://www.olddomain.com/home
    server: nginx centminmod
    x-powered-by: centminmod
    x-xss-protection: 1; mode=block
    x-content-type-options: nosniff
    
     
  4. eva2000

    eva2000 Administrator Staff Member

    45,201
    10,280
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +15,934
    Local Time:
    10:31 PM
    Nginx 1.19.x
    MariaDB 5.5/10.x
    I see some of the curl header's showing 302 redirect to 'location' listed olddomain. Did you import the wordpress database from olddomain into newdomain's wordpress database ? If so you have olddomain.com set in settings and need to update it in database

    You using redis nginx level cache ? Wonder if that could be the issue ? Tried clearing redis server cache ?
    Code (Text):
    redis-cli flushall
    nprestart
    

    try a diff compare of old and new nginx vhost files to see if there's differences
    Code (Text):
    diff -u /usr/local/nginx/conf/conf.d/olddomain.com.ssl.conf /usr/local/nginx/conf/conf.d/newdomain.com.ssl.conf
    

    and post it's output in CODE/CODEB tags