Speed Engine – Serve With

November 12, 2018 May 7, 2019

Deliver your website content with the best web service for the task. In the article “ClusterCS Speed Engine – Concepts” we’ve explained our concept of routing request types to specific web services. A quick example is whether you want to serve PHP with Apache or NGINX. Or maybe decide to improve server utilization and delivery speed by using a lightweight server such as Lighttpd or NGINX for serving static files (images, Javascripts, CSS).

“Serve With” action allows you to configure the web requests to be handled with a specific server if the associated conditions are met.

 

Since examples are easy to understand in this case, let’s go over a few scenarios.

1.  Serve static files with Lighttpd

This rule states that if the path component of the URL ends with common static file extensions, the rule should be handled by Lighttpd. It is a default rule added by ClusterCS when adding a new domain to instantly improve the server resource usage from your web site requests. In some occasions, your website script may not provide the resource at the exact URL location (for eg on the fly generated thumbnails in Drupal) which can lead to Lighttpd returning a 404 Not Found error. In such cases, you may disable or remove this rule so that traffic flows to your default backend service or to another rule that you create to better handle the situation. In certain occasion, these resources are generated on the fly by the script and you can often find great improvements if you replace the static files rule with a “Cache With” rule to intercept this traffic. This alleviates the problem of the script continuously generating resources on every request. For more information on “Cache With” action please read the following article “cache with

2. Serve with NGINX

It’s easy to send traffic to NGINX. Compared to Apache, NGINX lacks the capability to read .htaccess files which is a general standard for rewrite rules in most of the common scripts. Instead of relying on htaccess, rewrites must be placed in the NGINX server block. You can easily find resources to customize your NGINX setup and ClusterCS makes it possible to add those by customizing the corresponding block configuration.

Click Customize next to Serve With NGINX and you can enter your custom rules

The custom NGINX config in its basic form contains a series of variables marked with a starting and ending $ sign which is later replaced by corresponding values based on various rules. We advise against replacing or removing those as in most cases it will result in broken configurations. These elements should not interfere with any NGINX customizations you need to  and, in most cases, you need to add your rules at the end of the server block (before the last ‘}’ sign)

 

3. Serve with Apache

Apache is set as the default server in standard ClusterCS setups. If you need to change the default or force Apache in certain conditions in between other rules you define, this easy selector achieves this. The Speed Engine allows multiple “Serve With” rules and it´s very important to remember the order of the rules matter. Use the drag icon to arrange them in the correct order. With NGINX you can have different custom configs per each zone which makes it easy to configure various custom rules per location, Example cases can include a web site which contains several types of scripts under the same domain (eg. Drupal, WordPress, etc.)

96