Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
litespeed_wiki:cache:lscache:wordpress [2015/10/12 15:09] Michael Alegre [Server Level Settings] |
litespeed_wiki:cache:lscache:wordpress [2017/01/03 21:32] Michael Alegre Added Redirect. |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== LSCache + WordPress Configuration ====== | + | ~~REDIRECT>litespeed_wiki:cache:no-plugin-wordpress~~ |
- | + | ||
- | 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 WordPress, the Internets leading content management system, 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 LSCache's behavior. | + | |
- | + | ||
- | Below are some recommended configurations to enable LSCache and get it working with your WordPress site(s). | + | |
- | ===== Server Level Settings ===== | + | |
- | + | ||
- | From the LSWS WebAdmin Console navigate to **Server >> Cache**. | + | |
- | + | ||
- | Under **Cache Storage Settings**, set **Storage path** to the directory you want to use to store cached objects. | + | |
- | + | ||
- | For example: | + | |
- | + | ||
- | Storage Path: /tmp/diskcache | + | |
- | + | ||
- | It is recommended that this directory be on a dedicated disk or disk array in RAID 0 configuration. | + | |
- | + | ||
- | + | ||
- | **Note:** You will need to create the desired directory before setting it as the **Storage Path** through the WebAdmin. Do this through the command line. | + | |
- | + | ||
- | For example: | + | |
- | + | ||
- | mkdir /tmp/diskcache | + | |
- | chown nobody:nobody /tmp/diskcache | + | |
- | chmod 700 /tmp/diskcache | + | |
- | + | ||
- | + | ||
- | Under **Cache Policy**, we recommend using the following settings: | + | |
- | + | ||
- | Enable Cache:No | + | |
- | Cache Request with Query String:Yes | + | |
- | Cache Request with Cookie:Yes | + | |
- | Cache Response with Cookie:Yes | + | |
- | Ignore Request Cache-Control:Yes | + | |
- | Ignore Response Cache-Control:Yes | + | |
- | Enable Private Cache: No | + | |
- | + | ||
- | **Note:** **Enable Cache** has been set to "No" here as caching will instead be enabled in the next section through the use of rewrite rules to control what pages will be cached and for how long. | + | |
- | ===== Website Level Settings ===== | + | |
- | + | ||
- | In your .htaccess file, located in the document root of your website, add the following: | + | |
- | + | ||
- | <IfModule LiteSpeed> | + | |
- | # The following line is okay but can be omitted | + | |
- | CacheEnable public / | + | |
- | RewriteEngine on | + | |
- | RewriteCond %{REQUEST_METHOD} ^(HEAD|GET)$ | + | |
- | RewriteCond %{REQUEST_URI} !^(wp-admin|wp-login.php|wp-cron.php) | + | |
- | RewriteCond %{HTTP_COOKIE} !wordpress_logged_in_ | + | |
- | RewriteRule .* - [E=Cache-Control:max-age=120] | + | |
- | </IfModule> | + | |
- | + | ||
- | ===== Discussion ===== | + | |
- | __**Setting the homepage to be cached for less time than other pages**__ | + | |
- | + | ||
- | Example rewrite rule: | + | |
- | + | ||
- | <IfModule LiteSpeed> | + | |
- | RewriteEngine on | + | |
- | RewriteCond %{REQUEST_METHOD} ^(HEAD|GET)$ | + | |
- | RewriteCond %{REQUEST_URI} !^(wp-admin|wp-login.php|wp-cron.php) | + | |
- | RewriteCond %{HTTP_COOKIE} !wordpress_logged_in_ | + | |
- | RewriteRule ^$ - [E=Cache-Control:max-age=60,S=1] | + | |
- | # The homepage will be cached for 60 seconds. | + | |
- | RewriteRule .* - [E=Cache-Control:max-age=600] | + | |
- | # All other pages will be cached for 600 seconds. | + | |
- | </IfModule> | + | |
- | + | ||
- | + | ||
- | __**Caching two versions of each page (mobile and non-mobile)**__ | + | |
- | + | ||
- | Example rewrite rule: | + | |
- | + | ||
- | <IfModule LiteSpeed> | + | |
- | RewriteEngine on | + | |
- | RewriteCond %{HTTP_USER_AGENT} android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge\ |maemo|midp|mmp|opera\ m(ob|in)i|palm(\ os)?|pho$ | + | |
- | RewriteRule .* - [E=Cache-Control:vary=ismobile] | + | |
- | RewriteCond %{REQUEST_METHOD} ^(HEAD|GET)$ | + | |
- | RewriteCond %{REQUEST_URI} !^(wp-admin|wp-login.php|wp-cron.php) | + | |
- | RewriteCond %{HTTP_COOKIE} !wordpress_logged_in_ | + | |
- | RewriteRule .* - [E=Cache-Control:max-age=120] | + | |
- | </IfModule> | + | |
- | + | ||
- | **Note:** "E=Cache-Control:vary=ismobile" is available as of LSWS version 5.0.7. | + |