Welcome to Centmin Mod Community
Become a Member

Wordpress Wordpress Multisite + Redis + wp-rocket + Cloudflare on Subdomains

Discussion in 'Blogs & CMS usage' started by EckyBrazzz, Aug 22, 2019.

  1. EckyBrazzz

    EckyBrazzz Active Member

    587
    125
    43
    Mar 28, 2018
    >>>>Click here<<<< i'm nearby......
    Ratings:
    +231
    Local Time:
    3:29 AM
    1.17.x
    10.3.x
    Hi there all,

    This should become a tutorial for setting up a WordPress Multi site. This is not a thing that comes by default in Centmin mod and it needs a little setup and adjustments in the settings.

    There is an old post on the forum, pinned about that install, but it's a little outdated (2016)

    You need to install Redis on a good way, install just one main domain.ssl.conf and follow some exact steps to complete the setup. The main domain can't have www, and for now, adding subdomains works out of the box after adding an A record at your DNS (Cloudflare as we use it here)

    For now, it seems to work, but before I gone write down exactly the steps how to archive it I need some time to test it and fine tune it. Have some little issues.

    I came to the conclusion that a Multi site environment for me has to many benefits as I have many sites in different languages, but here is a little preview.

    Project_CMM_7290.png

    On a network setup you can select what you want to have by default inside your network, one super user and on each domain an administrator and the normal other users. With the plugin Controlled Admin Access you can create a kind of administrator with limited rights . There is so much to configure, and the options that it has I did not see before.
    Project_CMM_7291.png

    Project_CMM_7292.png
    Currently, my setup is with the Nginx Helper plug that creates a map, normally the nginx helper plug does not show as many options, but with multi-site it does some extra.
    Project_CMM_7293.png

    The same for WebPExpress plugin, that is for the entire network to generate your WebP format images on the fly. The Wp-Rocket can't be set up in a Network, gives a fatal error, but you can use it on each subdomain.

    Code (Text):
    1293:M 21 Aug 2019 07:45:19.803 * Calling fsync() on the AOF file.
    1293:M 21 Aug 2019 07:45:19.805 * Removing the pid file.
    1293:M 21 Aug 2019 07:45:19.805 # Redis is now ready to exit, bye bye...
    1303:C 21 Aug 2019 07:45:49.627 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    1303:C 21 Aug 2019 07:45:49.629 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=1303, just started
    1303:C 21 Aug 2019 07:45:49.630 # Configuration loaded
    1303:C 21 Aug 2019 07:45:49.630 * supervised by systemd, will signal readiness
                    _._                                                
               _.-``__ ''-._                                            
          _.-``    `.  `_.  ''-._           Redis 5.0.5 (00000000/0) 64 bit
      .-`` .-```.  ```\/    _.,_ ''-._                                  
     (    '      ,       .-`  | `,    )     Running in standalone mode
     |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
     |    `-._   `._    /     _.-'    |     PID: 1303
      `-._    `-._  `-./  _.-'    _.-'                                  
     |`-._`-._    `-.__.-'    _.-'_.-'|                                
     |    `-._`-._        _.-'_.-'    |           http://redis.io      
      `-._    `-._`-.__.-'_.-'    _.-'                                  
     |`-._`-._    `-.__.-'    _.-'_.-'|                                
     |    `-._`-._        _.-'_.-'    |                                
      `-._    `-._`-.__.-'_.-'    _.-'                                  
          `-._    `-.__.-'    _.-'                                      
              `-._        _.-'                                          
                  `-.__.-'                                              
    
    1303:M 21 Aug 2019 07:45:49.636 # Server initialized
    1303:M 21 Aug 2019 07:45:49.636 * Ready to accept connections
    


    PLEASE DON'T POST COMMENTS BELOW IF IT IS NOT RELATED TO THIS ISSUE OR IF YOU ALREADY HAVE QUESTIONS ON HOW TO SET IT UP AS I DON'T SUPPORT IT "YET".

    I WILL SUPPORT IT AFTERWARDS!
     
    • Informative Informative x 2
  2. EckyBrazzz

    EckyBrazzz Active Member

    587
    125
    43
    Mar 28, 2018
    >>>>Click here<<<< i'm nearby......
    Ratings:
    +231
    Local Time:
    3:29 AM
    1.17.x
    10.3.x
    Little preview info.

    To create this we need Cloudflare for the SSL.
    The first domain can't include www (in fact www is a subdomain)

    Create a normal installation with option 22-2 (Redis) and with SSL

    Plugin nginx Helper is installed by default with Redis, we need this as it has extra options when using Multi sites.

    Be careful with WebP Express. The way they get stored in the media gelaria is different. This also is for normal media.

    Enable Multi site by editing wp-config.php
    Code (Text):
    define('MULTISITE', true);
    define('SUBDOMAIN_INSTALL', true);
    define('DOMAIN_CURRENT_SITE', 'domain.com');
    define('PATH_CURRENT_SITE', '/');
    define('SITE_ID_CURRENT_SITE', 1);
    define('BLOG_ID_CURRENT_SITE', 1);
    /* That's all, stop editing! Happy publishing. */
    

    Edit created domain.ssl.conf
    Code (Text):
    #x# HTTPS-DEFAULT
    # server {
    #
    #   server_name xoommit.com www.xoommit.com;
    #   return 302 https://xoommit.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/domain.com/public/wp-content/uploads/nginx-helper/map.conf;
    }
    server {
      listen 443 ssl http2 reuseport;
      server_name domain.com sub1.domain.com sub2.domain.com sub3.domain.com <SNIPPED>;
    

    Part for Redis
    Code (Text):
    # Block nginx-help log from public viewing
    location ~* /wp-content/uploads/nginx-helper/ { deny all; }
    
        set $skip_cache 0;
    
       # exclude mobile devices from redis caching
       if ($redis_device = mobile) {
         set $skip_cache 1;
       }
    
        # POST requests and urls with a query string should always go to PHP
        if ($request_method = POST) {
            set $skip_cache 1;
        }
        if ($query_string != "") {
            set $skip_cache 1;
        }
    # Don't cache uris containing the following segments
    if ($request_uri ~* "\?add-to-cart=|/cart/|/my-account/|/checkout/|/shop/checkout/|/store/checkout/|/customer-dashboard/|/addons/|/wp-admin/|/xmlrpc.php|wp-.*.php|/feed/|index.php|-->more if needed
      set $skip_cache 1;
    }
    
    # Don't use the cache for logged in users or recent commenters
    if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in|edd_items_in_cart|woocommerce_items_in_cart") {
      set $skip_cache 1;
    }
    
        # 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;
        }
    


    Define what should be in your network (enabled or not)
    Every time you want to add a new subdomain you have to
    • edit server name --> add sub4.domain.com as example
    • create a A record that point to your IP
    • most common use is for internationl pages other languages, so create child themes and enable them for the network. You have to create a php function to rename the category,
    • Add new subdomain in the WP Admin panel.
    • DONE, configure it now
    Importing old existing domains.
    • Use import /export function of WordPress. Step by step don't try to do them all together
    • default limit is 1MB, try to set higher value if needed
    • test each step of the import, something might be broken due plugins
    • Images are a no go.
    Wp-Rocket --> Great works
    Code (Text):
    curl -I https://sub1.domain.com
    HTTP/1.1 200 OK
    Date: Tue, 27 Aug 2019 14:11:29 GMT
    Content-Type: text/html; charset=utf-8
    Connection: keep-alive
    Set-Cookie: __cfduid=da23d5cfba42f53aa46bc2927c94a15481566915089; expires=Wed, 26-Aug-20 14:11:29 GMT; path=/; domain=.domain.com; HttpOnly; Secure
    Last-Modified: Tue, 27 Aug 2019 06:26:16 GMT
    Vary: Accept-Encoding
    X-Powered-By: centminmod
    Vary: Accept-Encoding, Cookie
    Cache-Control: no-cache, no-store, must-revalidate
    X-Rocket-Nginx-Serving-Static: Yes
    X-Rocket-Nginx-Reason: /wp-content/cache/wp-rocket/sub1.domain.com///index-https.html_gzip
    X-Rocket-Nginx-File: /home/nginx/domains/domain.com/public/wp-content/cache/wp-rocket/sub1.domain.com///index-https.html_gzip
    Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
    X-Frame-Options: SAMEORIGIN
    X-XSS-Protection: 1; mode=block
    X-Content-Type-Options: nosniff
    X-UA-Compatible: ie=edge
    X-Frame-Options: SAMEORIGIN
    X-XSS-Protection: 1; mode=block
    X-UA-Compatible: ie=edge
    Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
    Server: cloudflare
    CF-RAY: 50cea28a9f62bf46-XXX
    

    Don't start this now, as far for now it works, but needs improvements. Created subdomains get A+ at openssllabs.com thanks to Cloudflare. I did not post all configurations, Redis for example needs to be setup correctly.

    PLEASE DON'T POST COMMENTS BELOW IF IT IS NOT RELATED TO THIS ISSUE OR IF YOU ALREADY HAVE QUESTIONS ON HOW TO SET IT UP AS I DON'T SUPPORT IT "YET".
    POST CORRECTIONS/SUGGESTION -> FINE WILL HELP A LOT

    I WILL SUPPORT IT AFTERWARDS!
     
    • Informative Informative x 1
  3. EckyBrazzz

    EckyBrazzz Active Member

    587
    125
    43
    Mar 28, 2018
    >>>>Click here<<<< i'm nearby......
    Ratings:
    +231
    Local Time:
    3:29 AM
    1.17.x
    10.3.x
    Not bad thanks to CMM and Cloudflare. Every subdomain A+. Only need to upgrade Cloudflare for SNI support, but as it is in test I'll wait for a while. Project_CMM_7294.png
     
    • Like Like x 1
  4. rdan

    rdan Well-Known Member

    4,605
    1,111
    113
    May 25, 2014
    Ratings:
    +1,632
    Local Time:
    2:29 PM
    Mainline
    10.2
    If you wish to make use of a custom SSL certificate that supports browsers without SNI support, you would need to upgrade to a Business plan and enable Legacy Client support when uploading the SSL certificate. Business plans support one custom SSL certificate per zone.
     
    • Agree Agree x 1
    • Informative Informative x 1
  5. EckyBrazzz

    EckyBrazzz Active Member

    587
    125
    43
    Mar 28, 2018
    >>>>Click here<<<< i'm nearby......
    Ratings:
    +231
    Local Time:
    3:29 AM
    1.17.x
    10.3.x
    @rdan That's why I wrote "I'll wait for a while."