vB seo + litespeed cache

Discussion in 'LiteSpeed Cache' started by NiteWave, Mar 22, 2011.

  1. NiteWave

    NiteWave Administrator

    We've enable litespeed cache on a living vB seo site successfully, the load dropped a lot during peak time, response has become faster.
    vBulletin 4.1.2
    vBSEO 3.6.0
    litespeed 4.0.20

    1. the cache plugin for vBulletin 3/4
    Code:
    <?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>
            <version>1.0</version>
            <url />
            <versioncheckurl />
            <dependencies>
            </dependencies>
            <codes>
            </codes>
            <templates>
            </templates>
            <plugins>
                    <plugin active="1" executionorder="1">
                            <title>Unset session id for guest users</title>
                            <hookname>global_start</hookname>
                            <phpcode><![CDATA[if($vbulletin->userinfo['userid'] <= 0)
    {
    $vbulletin->session->vars['sessionurl']  = '';
    $vbulletin->session->vars['sessionurl_q']  = '';
    }]]></phpcode>
                    </plugin>
                    <plugin active="1" executionorder="1">
                            <title>SET COOKIE FOR LOGGED IN USERS</title>
                            <hookname>login_verify_success</hookname>
                            <phpcode><![CDATA[if ($send_cookies AND $cookieuser)
    {
    // Cookie user
    vbsetcookie('imloggedin', 'yes', true, true, true);
    }
    else
    {
    // Not permanent
    vbsetcookie('imloggedin', 'yes', false, true, true);
    }]]></phpcode>
                    </plugin>
                    <plugin active="1" executionorder="1">
                            <title>Send X-LiteSpeed-Cache-Control header for logged in users</title>
                            <hookname>style_fetch</hookname>
                            <phpcode><![CDATA[// Do not cache logged in user pages
    if ( $vbulletin->userinfo['userid'] )
    {
            header('X-LiteSpeed-Cache-Control: no-cache');
    };]]></phpcode>
                    </plugin>
            </plugins>
            <phrases>
            </phrases>
            <options>
            </options>
            <helptopics>
            </helptopics>
            <cronentries>
            </cronentries>
            <faqentries>
            </faqentries>
    </product>
    
    save above code as litespeed_cache.xml, and using
    vBulletin Admin Control Panel(/admincp)->
    Plugins & Products->
    Add/Import Product
    to import above .xml.

    2.rewrite rule in vBulletin's home directory .htaccess
    #VBSEO -- original vbseo rules
    ....
    RewriteRule ^(.+)$ vbseo.php [L,QSA]
    ===>
    RewriteRule ^(.+)$ vbseo.php [QSA]

    #rules for litespeed cache:
    RewriteCond %{HTTP_COOKIE} !vbseo_loggedin=yes
    RewriteCond %{HTTP_COOKIE} !bb_userid=
    RewriteCond %{HTTP_COOKIE} !bb_password=
    #RewriteCond %{ORG_REQ_URI} ^/(index\.php|)$
    RewriteCond %{REQUEST_METHOD} ^HEAD|GET$
    RewriteCond %{QUERY_STRING} ^$
    RewriteRule (.*) - [L,E=Cache-Control:max-age=60]

    note:
    1. in fact nothing new here, just put all pieces together to make it simple
    2. the vBulletin plugin is based on the vB plugin for varnish as we always mentioned in past posts/blog.
    Boosting vBulletin Performance with Advanced Caching,the attached file product-boostv1.xml
    Last edited: Mar 22, 2011
  2. bhanuprasad1981

    bhanuprasad1981 New Member

    bit confusing for me , i created and installed plugin as mentioned, but struck at .htaccess i presently have this what should be there instead of it :-

    Code:
    # Comment the following line (add '#' at the beginning)
    # to disable mod_rewrite functions.
    # Please note: you still need to disable the hack in
    # the vBSEO control panel to stop url rewrites.
    RewriteEngine On
    
    # Some servers require the Rewritebase directive to be
    # enabled (remove '#' at the beginning to activate)
    # Please note: when enabled, you must include the path
    # to your root vB folder (i.e. RewriteBase /forums/)
    #RewriteBase /
    
    
    RewriteCond %{HTTP_HOST} ^mysite.org$ [OR]
    RewriteCond %{HTTP_HOST} ^www.mysite.org$
    RewriteRule ^/?$ "http\:\/\/www\.mysite\.org\/index\.php" [R=301,L]
    
    
    RewriteRule ^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L]
    
    RewriteCond %{REQUEST_URI} !(admincp/|modcp/|cron|vbseo_sitemap)
    RewriteRule ^((archive/)?(.*\.php(/.*)?))$ vbseo.php [L,QSA]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !/(admincp|modcp|clientscript|cpstyles|images)/
    RewriteRule ^(.+)$ vbseo.php [L,QSA]
    
    
    

    just quote me what has to be there in that .htaccess file

    thanks.
  3. NiteWave

    NiteWave Administrator

    the last line of your rewrite rule is
    RewriteRule ^(.+)$ vbseo.php [L,QSA]
    remove the "L", change to
    RewriteRule ^(.+)$ vbseo.php [QSA]

    then add those rules follow
    #rules for litespeed cache:
    in my first post to your .htaccess
  4. meto

    meto New Member

    As I understand we need 2cpu license to support that, correct?
  5. NiteWave

    NiteWave Administrator

  6. jdeg

    jdeg New Member

    I tried these settings without any luck. Only difference is I'm using 3.8.
  7. NiteWave

    NiteWave Administrator

    vB 3.8 should be ok.

    to be sure the cookie name is same as previous post:
    RewriteCond %{HTTP_COOKIE} !bb_userid=
    RewriteCond %{HTTP_COOKIE} !bb_password=

    it's customizable by vB admin. for example, if yours is myvb_userid, change above bb_ to myvb_
  8. ihstiv

    ihstiv New Member

    Thanks for this concise tutorial - I was able to implement it successfully in my forum.

    I do have a question about the htaccess rule updates, specifically, I'm wondering why we remove the 'L' from [L,QSA] - I have a few different rewrite rules that include the vbseo.php file, and I want to make sure that I should remove the 'L' from all of them, including here?

    RewriteRule content/([0-9]+)-([^/])+ forum/vbseo.php?vbseourl=content.php&r=$1 [L,R]

    I think the 'L' means, 'Last rule - stop processing', which makes sense so that it stops once a match is made, instead of continuing to rewrite if another match is made further down the list of rules.

    I don't understand how this bit plays into the caching feature.

    Can anyone enlighten me on this part a little?
  9. NiteWave

    NiteWave Administrator

    good question - there is a better solution. and we've been just aware that not a long time ago.

    I'd publish the new suggested rewrite rules by this chance:

    usually there exists such a rewriterule in .htaccess of document root:
    Code:
    RewriteCond %{HTTP_HOST} !^www\.mysite\.org$
    RewriteRule ^(.*)$ http://www.mysite.org/$1 [R=301,L]
    
    just insert the new cache related rules after above rules:
    Code:
    #rules for litespeed cache:
    RewriteCond %{HTTP_COOKIE} !vbseo_loggedin=yes
    RewriteCond %{HTTP_COOKIE} !bb_userid=
    RewriteCond %{HTTP_COOKIE} !bb_password=
    #RewriteCond %{ORG_REQ_URI} ^/(index\.php|)$
    RewriteCond %{REQUEST_METHOD} ^HEAD|GET$
    RewriteCond %{QUERY_STRING} ^$
    RewriteRule (.*) - [E=Cache-Control:max-age=60]
    and leave the rest rewrite rules there without change!
    the typical ones are:
    Code:
    RewriteRule ^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ vbseo_sitemap/vbseo_getsitemap.php?sitemap=$1 [L]
    
    RewriteCond %{REQUEST_URI} !(admincp/|modcp/|cron|vbseo_sitemap)
    RewriteRule ^((archive/)?(.*\.php(/.*)?))$ vbseo.php [L,QSA]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !/(admincp|modcp|clientscript|cpstyles|images)/
    RewriteRule ^(.+)$ vbseo.php [L,QSA]
    
    this make lsws cache function easier to use and less chance to make mistakes.
    Last edited: Jul 15, 2011
  10. ihstiv

    ihstiv New Member

    Ok - thanks for the update!

    to confirm, the latest approach is to leave the 'L' intact in the rule(s) containing 'vbseo.php' - instead of removing it as recommended previously.

    So use this:
    RewriteRule ^(.+)$ vbseo.php [L,QSA]

    ..and not this:
    RewriteRule ^(.+)$ vbseo.php [QSA]

    correct?
  11. NiteWave

    NiteWave Administrator

    you are right.

    Not only that rule, but also all other rewrite rules, leave them "as is", without change. for complex rewrite rules, it's very tricky and risky to change anything.
  12. ihstiv

    ihstiv New Member

    Ok - thanks. I'll make the necessary changes.

    two more questions:

    1. can you help me understand this line:
    #RewriteCond %{ORG_REQ_URI} ^/(index\.php|)$

    ..and why it is commented out?

    2. is there a way to use the 'private cache' feature in lsws for vbulletin/vbseo logged in members?
  13. NiteWave

    NiteWave Administrator

    1.please remove it:
    #RewriteCond %{ORG_REQ_URI} ^/(index\.php|)$
    it's for test purpose: enable cache for homepage only.
    if test pass, comment it out.

    2.we've no chance to test "private cache" with vB/vbseo yet.
  14. ihstiv

    ihstiv New Member

    I've found that moving the lsws rules to the top of the htaccess file tends to cause problems, including 404 errors. The only thing that solves the errors is to move the lsws rules below all existing VBSEO RewriteCond and RewriteRule statements.

    RedirectMatch and other statements can go below it w/o problem.

    Knowing this, does it still make sense to leave this line as-is:
    RewriteRule ^(.+)$ vbseo.php [L,QSA]

    ..or would it be better to change it to this?
    RewriteRule ^(.+)$ vbseo.php [QSA]

    Cheers
  15. freeballt

    freeballt New Member

    I'm wondering the same thing.

    I also tested this on 3.8.4 and it doesn't seem to execute this: "header('X-LiteSpeed-Cache-Control: no-cache');"

    Many of my users are complaining about being logged out, and when I look at it in firebug it doesn't seem to have no-cache in response.

    I also had to disable the plugin because if a user is IP banned, it will show an IP banned message to other users.
    Last edited: Jul 15, 2011
  16. NiteWave

    NiteWave Administrator

    this header "X-LiteSpeed-Cache-Control: no-cache" is used between litespeed processs and lsphp5 process, will not show in response header, so not seen by firebug

    can you test homepage only(as discussed before), or another page, the rule is like:
    RewriteCond %{ORG_REQ_URI} ^/test-this-page/)$
    and clear cache folder first. only after succeeded for 1 page, then move on.
  17. jdeg

    jdeg New Member

    I'm having the same issue - if I move the rules to the bottom nothing gets cached though.

    Has anyone figured this out?
  18. NiteWave

    NiteWave Administrator

    moving the rules to top is recommended. if not working, you can post your rules here to see if any change to improve them.
  19. jdeg

    jdeg New Member

    I was using your rewrite rules from the first post right after the
    RewriteCond %{HTTP_HOST} !^site\.net
    RewriteRule (.*) http://site.net/$1 [L,R=301]
  20. jdeg

    jdeg New Member

    I wonder if this has something to do with gzip being enabled?

Share This Page