By default, if cache has been enabled for a cPanel account, all of the content for the websites within the account will be cached, including dynamic content.
However it is possible to change what content is cached and how long it is cached with the use of the Cache-Control header.
There are multiple different ways to utilize the Cache-Control header to meet your exact needs.
NGINX looks for Cache-Control response headers that have been set by the origin. In the case of cPanel, the origin will always either be the Apache or LiteSpeed instance on the local server. This means that you can use the Header directive in the .htaccess or VirtualHost configuration to set the Cache-Control response headers as to control which pages resources and content are cached. You can read more about the Header directive here:
In addition to making use of the Header directive, you would need to use some sort of directive to select which URLs and content get the specific header that you set. There are a very large variety of options that Apache provides to accomplish this task, however, for the .htaccess file, the mod_rewrite directives will probably be the most common choice. The following stack overflow example shows how you might go about configuring this:
It is important to note that servers which use the CGI PHP hander strip any headers set within the .htacess. To work around this you can either switch to a different PHP Handler such as suPHP, or you can set the cache control headers in the virtualhost configuration with the steps outlined here:
Another possible implementation would be to set the Cache-Control response header from within the application its self before the response is passed to Apache for further processing. This type of implementation will vary based upon the scripting language that the application is built with, so you would need to contact your developer if you need this type of implementation.
If you are using PHP, you could consult with your developer about the use of the Header function:
Checking Cache Status
When configuring and testing the Cache-Control headers, you may use one or both of the following guides to enable the cache status so that you can determine when a cache hit was successful or not:
- How to add the X-Cache-Status header to NGINX to assist with optimizing and troubleshooting cache settings
- How to create a custom access log for NGINX that shows the cache status for each request