The setup of all sites on our servers involves two web servers. A front-end webserver (nginx) that handles SSL connections, load balancing and caching, and a back-end web server (Apache) that handles PageSpeed and runs your PHP application.

The front-end web server (nginx) obeys the cache policies that are defined in the headers delivered by Apache. This means that your web application, or overrides of default policies in the .htaccess file will affect the behavior of the front-end cache.

Examination of cache headers

Many frameworks change headers and set policies that are convenient for the developer, rather than tuned for performance or the production environment. Hence, you should check and know how your application behaves. This can be done by checking the headers of elements using your browser.

In the following example we are examining a css file generated by Magento. Magento overrides our server default settings (our servers default to 10 minutes), by setting the «Expires» header one week into the future. This means that both our front-end server and your web browser is told not to re-request this file before it expires.



Such behaviour can cause trouble while developing, because the css file does not refresh, although the file is changed. To get past this there are several options, but the simplest is to add a new and unique parameter to the file. For instance, a reference in HTML to styles.css could be rewritten to styles.css?v=1. When the non-cached HTML changes, this element will be treated as new both by our front-end webserver and the browser.

Servebolt Control Panel Settings
On the site's settings page there are three different cache settings. They control the behaviour of the front-end web server (nginx).

Caching: Off

When caching is off, nginx passes all requests back to the back end webserver (Apache), which delivers the requested file directly from the file system. This is resource intensive, and makes web pages load much slower. Therefore this setting should only be used while developing.

When «developer mode» is enabled, caching is also automatically set to Off (in addition, PageSpeed is also disabled while in developer mode).

Cache: Static Files (default setting)

Caching of static files is the preferred and-default setting. In this mode elements like images, javascript and style sheets are cached according to the headers provided by your web application, or by the Servebolt standard setup. The Servebolt standard setup is tuned for good performance and a fairly high level of convenience for the developer. Caching of static elements reduces the load on the back-end webserver, and speeds up loading of web pages.

The period of time an element is cached for varies on a http response code basis:

- 200 (OK) 30 minutes
- 301 (Redirect) 5 minutes
- 404 (Page not Found) 1 minute

Static files get a 7 week expiry header, which means that the elements are cached for up to 7 days in nginx and the users browser.

Cache: Static Files + Full-Page Cache

This setting also allows caching for HTML and PHP output. For PHP applications this will require that headers are properly set. For Magento and WooCommerce we maintain plugins that can be installed on your website, and that alter the default behaviour of these applications to work according to standards.
Was this article helpful?
Thank you!