This is an old revision of the document!


LSCache + Drupal Configuration

LSCache, similar to Varnish cache, is a simpler and more efficient page caching solution built-in to LiteSpeed Web Server. When used in conjunction with Drupal, you can expect significant performance gains with a quick and easy setup. Cache management is also made significantly easier and more flexible with the ability to use rewrite rules to customize cache behavior.

Below are some recommended configurations to enable LSCache and get it working with your Drupal site(s).

Server/VirtualHost level cache storage needs to be configured properly for your environment. Select your server setup from the Web Server Configuration section of our LiteSpeed Cache Installation Guide and follow the instructions to set the server/virtual host level cache root and cache policy.

At the top of your .htaccess file, located in the document root of your website, add the following:

########## Begin - Litespeed cache
<IfModule LiteSpeed>
  CacheDisable public /
  RewriteEngine On  
  RewriteCond %{REQUEST_METHOD} ^GET|HEAD|PURGE$
  RewriteCond %{HTTP_HOST} ^(www.)?your_domain_name.com [NC]
  RewriteCond %{REQUEST_URI} !admin|register|login [NC]
  RewriteCond %{HTTP_COOKIE} !SESS [NC]
  RewriteCond %{QUERY_STRING} !nocache
  RewriteRule .* - [E=Cache-Control:max-age=120]
</IfModule>
########## End - Litespeed cache

Note1: The “CacheDisable public /“ directive is used to help protect against globally enabled caching and is optional. Instead, the server's global cache settings should be checked to ensure that cache is not enabled globally. Do NOT use “CacheEnable public /“ here as it will enable caching for all URLs belonging to this virtual host, including admin pages.

Note2: Where “your_domain_name.com” is the web address of your Drupal site.

Note3: We recommend using a different domain for your backend so that you can add/edit/preview a website's content through the admin domain without worrying about these changes being cached and seen by visitors.

Note4: To get the non-cached version of a page, add the “nocache” query string to a URL.

For example

https://www.your_domain_name.com/about?nocache
https://www.your_domain_name.com/about?some_other_query_string&nocache

Please verify to see if you can see “X-LiteSpeed-Cache: hit” by following this wiki.

Please refer to this wiki.

  • Admin
  • Last modified: 2017/05/10 20:03
  • by Jackson Zhang