LSWS Cache + vBSEO (Guest Cache)


LSWS Cache can be setup for vBSEO with vB cache plugin for guest cache.


vBulletin 3/4
vBSEO 3.6.0
LiteSpeed WebServer 4.0+ (supports public cache)


1. Save the following Cache plugin for vBulletin 3/4 to a file say litespeed_cache.xml

<?xml version="1.0" encoding="ISO-8859-1"?>

<product productid="lswscache" active="1">
        <title>Litespeed Caching</title>
        <description>settings to make Litespeed page cache working right</description>
        <url />
        <versioncheckurl />
                <plugin active="1" executionorder="1">
                        <title>Unset session id for guest users</title>
                        <phpcode><![CDATA[if($vbulletin->userinfo['userid'] <= 0)
$vbulletin->session->vars['sessionurl']  = '';
$vbulletin->session->vars['sessionurl_q']  = '';
                <plugin active="1" executionorder="1">
                        <title>SET COOKIE FOR LOGGED IN USERS</title>
                        <phpcode><![CDATA[if ($send_cookies AND $cookieuser)
// Cookie user
vbsetcookie('imloggedin', 'yes', true, true, true);
// Not permanent
vbsetcookie('imloggedin', 'yes', false, true, true);
                <plugin active="1" executionorder="1">
                        <title>Send X-LiteSpeed-Cache-Control header for logged in users</title>
                        <phpcode><![CDATA[// Do not cache logged in user pages
if ( $vbulletin->userinfo['userid'] )
        header('X-LiteSpeed-Cache-Control: no-cache');

2. Add the xml in 1. to vBulletin

 Log into Admin Console Panel (http://site/forum/admincp)
    Plugins & Products => Add/Import Product)

3. Modify rewrite rules in .htaccess

Rewrite Rules: on the very beginning, maybe just after

RewriteEngine On


#rules for litespeed cache: begin
RewriteCond %{HTTP_COOKIE} !vbseo_loggedin=yes
RewriteCond %{HTTP_COOKIE} !bbuserid=
RewriteCond %{HTTP_COOKIE} !bbpassword=
#RewriteCond %{ORG_REQ_URI} ^/(index\.php|)$
RewriteCond %{QUERY_STRING} ^$
RewriteRule (.*) - [E=Cache-Control:max-age=60]
#rules for litespeed cache: end

no need change other rewrite rules which comes from vBSEO or other sources.

4. Enable and Set up Cache Policy in LSWS

In LiteSpeed (v4.1.2 or later) Admin CP → Configuration → Server → Cache

Storage Path: /diskcache
Max Object Size: 128K

Cache Policy
Enable Cache:    No
Cache Expire Time (seconds):    Not Set
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
Private Cache Expire Time (seconds):    
Do-Not-Cache URL(s):


  1. Cache storage can be set to /dev/shm/diskcache to avoid disk I/O wait if enough memory can be spared.
  2. Cache resource with size less than 128KB.
  3. your vB's coookie name may vary, for example my_userid instead of bbuserid, depend on your vB configuration.
  4. For cached request, “X-LiteSpeed-Cache: hit” response header should be seen. IOW, if no such entry in the response header, the response is not cached by LSWS.

Crate a cronjob to clean up stale cache

*/10 * * * * find /diskcache -type f -mmin +10 –delete

Note: This cron job clean up stale cache storage every 10 minutes.

Add entries to /etc/rc.local

   echo "mkdir /diskcache && chmod nobody.lsadm" >> /etc/rc.local
   echo "/diskcache && chmod 770 /diskcache" >> /etc/rc.local

Note: this is to make sure cache directory gets created when server is booted up.

litespeed_wiki/litespeed/cache/vbulletin.txt · Last modified: 2014/08/08 01:24 by Gary Duan