Archive for August, 2018


Engintron and mirrors

This is pretty much the same thing as what I did in a previous post, but with Engintron vs NGINX CP.  I had to do a lot of server updates to get PHP7 running, and the process broke NGINX CP, so I had to switch to Engintron.  NGINX by itself is much more efficient than Apache, and thus far has been plenty to keep the server running even when traffic spikes.  But for special occasions I do like to have a back-up plan in case the system gets overloaded so I have a mirror set and ready to go.

To first install Engintron you can follow these instructions:

  1. cd /
  2. rm -f engintron.sh
  3. wget –no-check-certificate https://raw.githubusercontent.com/engintron/engintron/master/engintron.sh
  4. bash engintron.sh install

One thing I found out is caching is not on for dynamic pages by default, in order to turn that on go to the Enigtron interface from WHM, then click on “Edit default.conf” find this code:

1
2
 set $CACHE_BYPASS_FOR_DYNAMIC 1;
 set $CACHE_BYPASS_FOR_STATIC 0;

and set it to:

1
2
 set $CACHE_BYPASS_FOR_DYNAMIC 0;
 set $CACHE_BYPASS_FOR_STATIC 0;

“bypass_for_dynamic” will essentially turn off caching for dynamic pages, if your dynamic pages aren’t being updated very often it’s best to have caching on.  If you have a specific page that cannot by cached you can turn the bypass back on using something like this:

1
2
3
 if ($SITE_URI ~* "yourdomain.com/url_to_not_cache") {
    set $CACHE_BYPASS_FOR_DYNAMIC 1;
 }

Like previously I’m using  the split clients module to spread out traffic to a mirror.  The logic here is a bit more tricky then in NGINX CP and I only have one mirror, so the $mirror variable is just determining whether or not I’ll be redirecting that user.  The code looks essentially like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
split_clients "${remote_addr}-{$query_string}" $mirror {
   5% "y";
   * "n";
}
 
server {
 
   if ($SITE_URI ~* "domain.com") {
      set $mirror "${mirror}maindomain";
   }
   if ($http_referer = "") {
      set $mirror "n";
   }
   if ($mirror = "ymaindomain") {
      return 302 "http://mirror.yourdomain.com/";
   }
 
}

So here the split_clients will set the $mirror variable to “y” 5% of the time.  Then, if the domain is “domain.com” it will set the $mirror variable to either “ymaindomain” or “nmaindomain” and the http_referer is just stopping all direct traffic from being redirected to the mirror.  The reason I’m changing the variable is so I don’t end up mirroring subdomains, and I could use that to have different mirrors for different subdomains or specific pages.

Permalink » No comments