{"id":224,"date":"2011-01-28T20:31:29","date_gmt":"2011-01-29T00:31:29","guid":{"rendered":"http:\/\/blog.litespeedtech.com\/?p=224"},"modified":"2011-01-28T20:31:29","modified_gmt":"2011-01-29T00:31:29","slug":"speed-up-vbulletin-sites-through-litespeed-built-in-cache","status":"publish","type":"post","link":"https:\/\/lswp.store\/index.php\/2011\/01\/28\/speed-up-vbulletin-sites-through-litespeed-built-in-cache\/","title":{"rendered":"Speed Up vBulletin Sites Through LiteSpeed Built-in Cache"},"content":{"rendered":"<p>LiteSpeed has provided a built-in cache functionality (an advanced feature for Enterprise 2+CPU licenses) since version 4.0 (March, 2009), and keeps improving this feature through subsequent 4.0.x releases. Many of you maybe still not aware of the powerfulness of this feature. <!--more-->\u00a0This article will show a sample usage for the popular vBulletin \u00a0forum with detailed steps, and you are welcome to post your feedback on your real-life exciting results.<\/p>\n<p>LiteSpeed cache has similar features as Apache mod_cache but implemented in a more efficient way, and works like Varnish. It is an output cache for dynamic contents, so the usage does not limit to PHP pages. \u00a0Unlike \u00a0Varnish, it is built into the web server, reducing one layer of reverse proxy. Hence for static contents it is more efficient without one extra layer. \u00a0The uniqueness of LiteSpeed cache is that you can use rewrite rules (either in configuration files or .htaccess) to control its behavior, which gives you maximum flexibility.<\/p>\n<p><strong>Sample Use Case for vBulletin forums <\/strong>(vB 3.8.x or vB 4.0.x)<\/p>\n<p>Here we give one example of how to use LiteSpeed cache with rewrite rules to speed up vBulletin forums. We would like to cache the pages for guest users, which generate the majority of the traffic.<\/p>\n<p><strong>1. Install vBulletin plug-in &#8211; Boost Product XML<\/strong> \u201cproduct-boostv1.xml\u201d from vBulletin admin panel \u2013 manage plugin.<\/p>\n<p>You can download from <a href=\"http:\/\/vbulletin.com\/forum\/entry.php?2440-vB4Mance-Part-5-Expert-Level-Boosting-vBulletin-Performance-with-Advanced-Caching\" target=\"_blank\">here<\/a>.\u00a0It is a good article elaborating about why output cache is essential for high traffic sites. \u00a0The purpose of this plug-in is to determine if the user is a guest user or a logged in member. You do not need boost.php, that\u2019s for Varnish only.<\/p>\n<p><strong>2. Enable the cache function. <\/strong>You have to go to the LiteSpeed admin console to set this up, mod_cache config for \u201cCacheRoot\u201d will be ignored.<\/p>\n<p>a. Go to admin console-&gt;Server-&gt;Cache<\/p>\n<p>b.\u00a0Cache Storage Settings-&gt;Storage Path: set to a fast local disk, for e.g.: \/tmp\/diskcache (you can also set it to a ramdisk if you have enough extra memory to speed up further)<\/p>\n<p>c. Manually create the directory from shell, and give permission for litespeed\/lshttpd processes (assume running as &#8220;nobody&#8221; here):<\/p>\n<blockquote><p>#mkdir \/tmp\/diskcache<br \/>\n#chown nobody:nobody \/tmp\/diskcache<br \/>\n#chmod 700 \/tmp\/diskcache<\/p><\/blockquote>\n<p><strong>3. Set vhost Cache policy<\/strong><\/p>\n<p>a. For <em>natively configured vhost<\/em> (for e.g. myforum) in admin console:<\/p>\n<p>i. \u00a0Go to admin console-&gt;Virtual Hosts-&gt;myforum-&gt;Cache<\/p>\n<p>ii. \u00a0Disable the cache globally (will be enabled through rewrite rules under condition)<\/p>\n<blockquote><p>Enable Cache:No<\/p><\/blockquote>\n<p>iii. Set cache policy<\/p>\n<blockquote><p>Cache Request with Query String:Yes<br \/>\nCache Request with Cookie:Yes<br \/>\nCache Response with Cookie:Yes<br \/>\nIgnore Request Cache-Control:Yes<br \/>\nIgnore Response Cache-Control:Yes<\/p><\/blockquote>\n<p>b. For <em>imported Apache vhost<\/em>:<\/p>\n<p>There is no need to use mod_cache directive to control cache. You do not need to do anything for the vhost cache policy. It will assume the same default settings as the above natively configured vhost. However, you do need to set the server level Cache storage from the Litespeed web admin console stated in step 2; and put rewrite rules in the .htaccess file as in step 4.<\/p>\n<p><strong>4. Add rewrite rules<\/strong> to cache guest pages for 2 minutes<\/p>\n<p>Assuming vBulletin is installed at $DOCUMENT_ROOT\/forum<\/p>\n<blockquote><p>## following redirect will reduce cached files:<br \/>\n## otherwise domain.com\/abc.php and www.domain.com\/abc.php will create 2 cached files.<br \/>\nRewriteCond %{HTTP_HOST} !^www\\.domain\\.com$<br \/>\nRewriteRule \/forum\/(.*)$ http:\/\/www.domain.com\/forum\/$1 [R=301,L]<\/p>\n<p>## select which pages to cache<br \/>\nRewriteCond %{HTTP_COOKIE} !bbimloggedin=yes<br \/>\nRewriteCond %{HTTP_COOKIE} !bbuserid=<br \/>\nRewriteCond %{HTTP_COOKIE} !bbpassword=<br \/>\nRewriteCond %{REQUEST_METHOD} ^HEAD|GET$<br \/>\nRewriteCond %{QUERY_STRING} !s=[a-fA-F0-9]{32}<br \/>\nRewriteCond %{QUERY_STRING} !product=vbnexus<br \/>\nRewriteCond %{REQUEST_URI} !^\/forum\/(login|register|usercp|private|profile|cron|image) \\.php$<br \/>\nRewriteCond %{REQUEST_URI} !^\/forum\/admincp<br \/>\nRewriteRule \/forum\/(.*\\.php)?$ &#8211; [L,E=Cache-Control:max-age=120]<\/p><\/blockquote>\n<p>You can add the rewrite rules in either of the 3 locations:<\/p>\n<ul>\n<li>.htaccess\u00a0 (adding a line at beginning: \u201cRewriteEngine on\u201d)<\/li>\n<li>Apache config file vhost section<\/li>\n<li>Litespeed natively configured vhost: admin console-&gt;Virtual Hosts-&gt;myforum-&gt;Rewrite<\/li>\n<\/ul>\n<p><strong>5. \u00a0Apply changes by restarting LiteSpeed<\/strong><\/p>\n<p><strong>6. \u00a0Optional: \u00a0Set a cron job to clean up cache<\/strong> directory \/tmp\/diskcache<\/p>\n<blockquote><p>*\/10 * * * * root find \/tmp\/diskcache -type f -mmin +8 -delete 2&gt;\/dev\/null<\/p><\/blockquote>\n<p>Every 10 minutes, delete cached files that are more than 8 minutes old. Since we set the cache expire time as 120 seconds (2 minutes),\u00a0 it&#8217;s safe to delete those old files.<\/p>\n<p><strong>7.\u00a0Verify if pages are served from the cache<\/strong><\/p>\n<p>Since 4.0.19, LiteSpeed will output a response header \u201cX-LiteSpeed-Cache hit\u201d if the content is served from its internal cache.<\/p>\n<p><strong>8. Optional: If you want to log cache hit data<\/strong> for future analytics, you can use the environment variable \u201cCACHE_HIT=1\u201d (introduced in 4.0.19) in your in customized access log with format string \u201c%{CACHE_HIT}e\u201d.<\/p>\n<p>For example: in the httpd.conf vhost section, add<\/p>\n<blockquote><p>CustomLog \/usr\/local\/apache\/domlogs\/domamin.com-cache_log &#8220;%h %t \\&#8221;%r\\&#8221; %&gt;s %b %{CACHE_HIT}e&#8221;<\/p><\/blockquote>\n<p><strong><em>Reference:<\/em><\/strong><\/p>\n<ol>\n<li>How does the output cache work? <a href=\"\/vbulletin.com\/forum\/entry.php?2440-vB4Mance-Part-5-Expert-Level-Boosting-vBulletin-Performance-with-Advanced-Caching\" target=\"_blank\">vBulletion forum<\/a><\/li>\n<li>Big boost: related posts at <a href=\"http:\/\/www.litespeedtech.com\/support\/forum\/forumdisplay.php?f=30\">our forum<\/a>.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>LiteSpeed has provided a built-in cache functionality (an advanced feature for Enterprise 2+CPU licenses) since version 4.0 (March, 2009), and keeps improving this feature through subsequent 4.0.x releases. Many of you maybe still not aware of the powerfulness of this feature.<\/p>\n","protected":false},"author":1,"featured_media":6685,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[27,28,20],"tags":[297],"class_list":["post-224","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-web-server","category-cache","category-performance","tag-vbulletin"],"jetpack_featured_media_url":"https:\/\/lswp.store\/wp-content\/uploads\/2016\/11\/imageNov82016.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/posts\/224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/comments?post=224"}],"version-history":[{"count":0,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/posts\/224\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/media\/6685"}],"wp:attachment":[{"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/media?parent=224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/categories?post=224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lswp.store\/index.php\/wp-json\/wp\/v2\/tags?post=224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}