Nginx Cache Configuration

Nginx's global settings allow you to change the default values ​​used by the module on each site. So be very careful when editing, a bad modification could cause damage to some sites like session sharing on online shops.

The module will assign different priorities if multiple values are available for the same site. It is therefore likely that a site does not use the default settings.

The module will first check if the user has created a configuration for a particular site, then it will check if a user has a global configuration for all its sites and finally he will use the default settings.


The settings have been classified into several categories to ease navigation.

When a user changes the advanced settings inside the cPanel panel, the "Statics" category includes the categories of the following WHM interface:

  • Static files
  • Images files
  • Archives, Medias and document files
  • Font files

This is to simplify the configuration for users.

Here is the description of each category:

Gzip compression :

Enable or disable Gzip compression on all pages served by Nginx.

Dynamic files :

Allows you to change the settings of dynamic files.

Dynamic files are all files sent as HTML to the browser, so this category includes PHP files (once compiled) and static HTML files.

Static files :

By default, the category groups Json, xml, rss and atom files.

Cascading Style Sheet and Javascript (CSS and JS) :

By default, the category groups the files css and js.

Images files :

By default, the category groups ico, jpg, jpeg, gif, png, webp files.

Archives, Medias and document files :

By default, the category groups 3gp, 7z, avi, bmp, bz2, csv, divx, doc, docx, eot, exe, flac, flv, gz, less, mid, midi, mka, mkv, mov, mp3 files, mp4, mpeg, mpg, odp, ods, odt, ogg, ogm, ogv, opp, pdf, ppt, pptx, rar, rtf, swf, tar, tbz, tgz, tiff, txz, wav, webm, wma, wmv, xls, xlsx, xz, zip.

Fonts files :                             

By default, the category groups the files eot, ttf, otf, woff, woff2, svg, svgz.

Category settings

Each category has several common settings. For each setting, you can click on the question mark icon for a brief description of its functionality.

At each of the settings, the initial parameters of the module remain indicated, so it is possible at any time to easily reset the default settings.

Here is a description of each of the settings.

Enable server side caching :

When the option is enabled, it gives the Nginx server the option of placing item in the cache according to the other settings.

Allow Nginx to update the cache file in a background process :

Allows Nginx to serve a cache item even if it is considered too old. This option also allows Nginx to serve a cache item (if available) when the Apache server is unable to serve it. For example, if the Apache server returns a 500 error, Nginx can be asked to serve the version of the cached item even if it is no longer considered valid.

If the Apache server is still running, at the same time that Nginx is serving an item that is too old from the cache, it will make a request to the Apache server to update the version of the item it has in its cache. This behavior prevents visitors to a site from waiting longer when the cache needs to be refreshed.

This setting is available only for dynamic content and is called server stale content.

Force the browser cache :

This setting allows Nginx to send instruction to ask the client's browser to keep a copy of the item in its local cache.

It is important to take into consideration that if an item is in the local cache of a browser, it is not possible for the module to purge it remotely. Great care must be taken when activating this function for dynamic content, but it is advisable to activate it for all static content.

This setting is available only for dynamic content, for static content we simply need to specify the time that the item should remain in the browser cache.

Browser cache expire time :

This setting defines the time that the browser should keep an item in its local cache. The setting is taken into consideration only if the "Force the browser cache" setting is enabled.

Bypass cache control :

Several CMS (like WordPress, Joomla, Drupal, etc.) will sometimes set parameters in the headers of HTML requests to warn not to keep a copy of some cached pages. These settings are "Cache-Control", "Expires" and "Pragma".

This option allows Nginx to ignore these headers when it analyzes whether to put the page in its cache.

Note: This option is available only with dynamic content.

URI string that should not be cached.  :

In this setting we can define parts of a URI that should never be placed in the cache. As soon as Nginx sees an address with a URI corresponding to one of those in the list, it will place the request in "Bypass" mode so as not to place the item in its cache.

Note: It is important to separate each item by a comma in the list.

Cookies that should not be cached.  :

We can put a list of cookies that should never be placed in Nginx's cache. If one of these is present on a page, it will be classified as "Bypass" to not be placed in the cache.

This setting is available only for dynamic content.

Note: It is important to separate each item by a comma in the list.

Stale cache : Serve cache file for the following scenarios :

This setting allows you to choose for which cases Nginx is allowed to serve an item in the cache even if the cache is considered expired.

This function can be activated for the following scenarios:

  • Backend error message: The Apache server returns an unknown error.
  • Backend timeout  The Apache server did not have time to respond within the prescribed time.
  • Invalid header: The header of the item sent by Apache is not valid.
  • Cache begin updated: The item in the cache is no longer valid, Nginx will refresh it in the background.
  • 403 error: Access prohibited.
  • 404 error: Element not found.
  • 500 error: Apache server error, it can not understand the requested settings.
  • 502 error : Gateway error, Nginx can not join the Apache server.
  • 503 error : Service not available.
  • 504 error : Waiting time of the gateway has been exceeded.

Backend server response code for caching :

This setting makes it possible to decide which answer code Apache is considered acceptable for the item to be placed in the cache.

Note: It is important to separate each item by a comma in the list.

Amount of time the page can stay in Nginx cache :

Define the number of times an item can be kept inside the Nginx cache before being considered "STALE".