HowTo: Configure Vbulletin To Use A Content Delivery Network (CDN)

Posted on in Categories Apache, lighttpd, Networking last updated June 11, 2010

The last time I wrote about CDN, I wrote about how to configure CDN for wordpress to speed up your wordpress blog to display content to users faster and more efficiently. However, a few regular readers like to know how to configure the Amazon CDN or other CDN network to use with Vbulletin forum software. In this quick tutorial, I will explains how to configure Vbulletin, Apache/Lighttpd webserver, Bind dns server to use a CDN to distribute your common files such as css, js, user uploaded files and lighten load on your web server.

Our Sample Forum Setup

  1. Forum URL : – This is hosted on your own server using Apache, Lighttpd, or Nginx.
  2. Origin Pull URL : – This is hosted on your own server. You need to configure your web server, vbulletin and dns server to use this. This is called as “Origin Pull Host” which is a CDN method by which content is pulled from your web server.
  3. CDN URL : – This is a cdn url hosted by your CDN provider such as Amazon. This url always point to an edge server via proprietary DNS hacks. must be set as CNAME records which will point to domain names of CDN server.
  4. CDN DNS CNAME : – is your CDN provider. This is must be set as CNAME for

Step # 1: Purchase CDN Service

As I said earlier the cost varies between CDN providers. Check CDN service providers website for more information. Next, you need to use service providers “control panel” to configure an “Origin Pull Host” for each domain. In other words configure in origin pull mode. The control panel will also provide your an option to setup CDN dns CNAME. You need to use same CNAME in step # 2. Once the configuration is active and the CNAME is resolving, calls to will be cached from

Step # 2: Update Your DNS Server

I’m assuming that you are using BIND dns server edit your zone file and add entry as follows (you can skip this step and use your ISP’s dns hosting providers control panel to setup CNAME and origin host):

; CDN CNAME mapping for
cdn                 3660       IN CNAME
; Your cdn-origin url (note is also hosted on same server IP
cdn-origin        3600       IN A

Save and close the file. Reload named:
# rndc reload && tail -f /var/log/messages
To keep your configuration simple use the same web server for origin pull domain and main domain i.e. host both and on same web server. This allows you to directly upload and map files to the CDN server.

Step # 3: Configure Origin Pull Web Server

You need to configure as follows:

  1. Origin pull DocumentRoot: /home/httpd/ – All your .css, .js and uploaded files are hosted here.
  2. Server Forum DocumentRoot: /home/httpd/ – All your vbulletin files are hosted here.
  3. MaxAge: Set cache-lifetime headers for static files for cdn network.
  4. Etags: An ETag (entity tag) is part of HTTP, the protocol for the World Wide Web. It is a response header that may be returned by an HTTP/1.1 compliant web server and is used to determine change in content at a given URL. When a new HTTP response contains the same ETag as an older HTTP response, the client can conclude that the content is the same without further downloading.

Sample Apache Configuration

<virtualHost >
	ServerAdmin [email protected]
	DocumentRoot /home/httpd/
	ErrorLog /var/logs/httpd/cdn-error_log
	CustomLog /var/logs/httpd/cdn-access_log common
	# Files in this directory will be cached for 1 week only.
	# After 1 week, CDN server will check if the contents has been modified or not.
	# If not modified, Apache will send 304 "Not Modified" header
	<directory "/userimages">
		Header set Cache-Control "max-age=604800, must-revalidate"
	# Disable ETag as we are on cluster Apache server
	<directory "/pdfs">
		Header unset ETag
		FileETag None
	# Do not cache
	<directory "/patches">
		Header Set Cache-Control "max-age=0, no-store"

Sample Lighttpd Configuration

# Configure ETags
etag.use-inode = "enable"
etag.use-mtime = "enable"
etag.use-size = "enable"
static-file.etags = "enable"
###### CDN FILES via Wordpress Upload ##############
$HTTP["host"]  == ""{
        server.document-root = "/home/httpd/"
        accesslog.filename         = "/var/log/lighttpd/cdn.access.log"
	#  Set max age
        $HTTP["url"] =~ "^/" {
            expire.url = ( "" => "access 60 days" )

Adjust documentroot as per your setup.

Step # 4: Create Required Directories

You need to configure files for
# mkdir -p /home/httpd/
# cd /home/httpd/

Next, soft link your .css, .js, images, clientscripts files against original forum documentroot (i.e. /home/httpd/ as follows:
# ln -s ../ .
# ln -s ../ .
# ln -s ../ .
# ln -s ../ .
# ln -s ../ .
# ln -s ../ .

Again, feel free to adjust paths according to your setup. Test your new cdn urls:

Step # 5: Configure Vbulletin To Use a CDN Server

You need to edit your vbulletin style. Open admincp by visiting > Select Styles & Templates > Replacement Variable Manager:

Fig.01: Vbulletin Editing Styles And Templates
Fig.01: Vbulletin Editing Styles And Templates

Click on [Add New Replacement Variable] link and set it as follows:

  • Set Search for Text to href=”clientscript
  • Set Replace with Text to href=”

Sample outputs:

Fig.02: Vbulletin Adding Replacement Variable For CDN
Fig.02: Vbulletin Adding Replacement Variable For CDN

You need to repeat this step for images, javascript and other shared media as follows:

Search for TextReplace with Text
src=”clear.gif” src=””
src=”customavatars/ src=”
src=”customprofilepics/ src=”
src=”images/ src=”
url(“clientscript url(“
src=”clientscript/ src=”
href=”clientscript/ href=”
url(./images/ url(
url(images/ url(
var imgdir_misc = “images/misc”; var IMGDIR_MISC = “”;

Avatars & Pictures – Storage Type

Visit Avatars > Storage Type and set them as follows to match your above CDN rules by moving all of them to file systems:

  • Avatars are currently being served from the filesystem at ./customavatars
  • Profile pictures are currently being served from the filesystem at ./customprofilepics
  • Signature pictures are currently being served from the filesystem at ./signaturepics

How Do I Test Images And Other Media Files Are Cached Or Not By CDN?

Use curl to test HTTP headers (look for Etags, max-age and Expires headers):
$ curl -I ''
$ curl -I


The forum home page loading (rendering) time went from 8.5 seconds to 2.2 seconds and average thread loading time went from 14.3 seconds to 5 seconds:

Fig.03 Speed Improvements With CDN
Fig.03 Speed Improvements With CDN

See 6 tools to test web site speed for more information.

Recommend readings:

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

25 comment

    1. Many thanks for this! I used it yesterday to set up my Vbulletin and it worked great.

      I had one question, and that is the purpose of the Sim Links? I was thinking they were in case the CDN goes down that the images/javascript etc would still load from the subdomain, is this correct? I really don’t see any other purpose for them.

      Thanks again!

  1. Many thanks Vivek,

    I found your article interesting, and well-done.
    Your work do cover a very broad spectrum of IT!
    Keep up the good work, man. πŸ™‚

    — Philippe

  2. Great article!

    Is there much benefit of using a CDN if most of your visitors are from the same country that your server resides in?

    I imagine though that the CDN will provide improved page load speeds due to parallel downloading and improved management of cached content?

    1. It ALL depends upon your cdn providers network. Some large CDN providers have multiple edge servers in same country. For example, large provider such as Akamai does provide multiple edge servers so you end up speeding up website. However, some provider only got 1 edge server. So you need to do your own research before purchasing such CDN.


    1. There are different types of CDN. The CDN discussed in this article is for caching static files. You need to use “Dynamic Content Acceleration” with SSL (optional for securing data transfer). Checkout the list posted at wordpress CDN article, and most large CDN provider also provides Dynamic Content Acceleration.


  3. Thanks for posting this guide.

    I’m not sure, but I may have found a small mistake. In your first replacement variable example, shouldn’t the following:


    instead be:



  4. hell yea.thanx for sharing this post with me.i just found it buy google couse i was searching for
    more info about this.Ang WOOHOO! i found your post that was so usefull for me πŸ™‚
    feel free to drop me email i will send small donation! love for all you here.

  5. (oops I replied to another post by mistake instead of leaving a new comment, sorry)

    Many thanks for this! I used it to set up my Vbulletin and it worked great.

    I had one question, and that is the purpose of the Sim Links? I was thinking they were in case the CDN goes down that the images/javascript etc would still load from the subdomain, is this correct? I really donÒ€ℒt see any other purpose for them.

    Thanks again!

  6. I am stuck on this step:
    # ln -s ../ .
    # ln -s ../ .
    # ln -s ../ .
    # ln -s ../ .
    # ln -s ../ .
    # ln -s ../ .

    I tried to create soft link but it doesn’t work
    it doesn’t create a link, just a custom file.

    Can you help?

  7. Hi Vivek,

    It worked… however partially. I have some other folders such as xyz under images folder. But they are not getting redirected to CDN.

    for eg: contents of images/xyz are not getting redirected.

    however, contents of images/providers are getting redirected..

    any idea ???

  8. Hello,

    The directions above worked for me but I’m having trouble adding more paths to the CDN. For example I would like to include /attachments and /arcade. I tried following the other examples as a guide but looking at the page src and hovering over pieces of my thread pages they don’t appear to be loaded via the CDN like /clientscript and /images. Is it possible to CDN more parts of my vBulletin?

    Thank you, -Nick

Leave a Comment