WordPress optimization with cdn and wp super cache plugin

What Is A CDN?

A content delivery network or content distribution network (CDN) is a system of computers containing copies of data, placed at various points in a network so as to maximize bandwidth for access to the data from clients throughout the network. A client accesses a copy of the data near to the client, as opposed to all clients accessing the same central server, so as to avoid bottleneck near that server. A cdn will increase speed and efficiency for your blog.

Ok, let’s begin. I have debian box for the tests.

First, we have host example.com , we need to create CNAME cdn.example.com in our bind zone. After that we will install lighttpd to serve cdn contents ->

apt-get install lighttpd

and nginx with varnish for everything else 🙂

In my lighttpd.conf I put line to change the default port to 88


server.port = 88

After that I create vhost.conf with:

etag.use-inode = “enable”
etag.use-mtime = “enable”
etag.use-size = “enable”
static-file.etags = “enable”

###### CDN FILES via WordPress Upload ##############
$HTTP["host"]  == “cdn.friendbg.net”{
server.document-root = “/var/www/cdn”
accesslog.filename         = “/var/log/lighttpd/cdn.access.log”
#  Set max age
$HTTP["url"] =~ “^/” {
expire.url = ( “” => “access 60 days” )
}
}


After this restart the lighttpd daemon.

So .. now go to wp-admin , settings , media and go to Uploading Files section.

Now change the directory “Store uploads in this folder” to “/var/www/cdn” and “Full URL path to files” to https://cdn.example.com:88

Don’t forget to change the permissions to 777 or to www-data to directory /var/www/cdn

With this change every file uploaded to your blog will be stored to /var/www/cdn and will be accessed by https://cdn.example.com:88

Now is time to install wp super cache plugin and after the successful install we need to configure it.

Go to Settings,WP super cache , WP Super Cache Settings , CDN and check this: Enable CDN Support

On Off-site URL : https://cdn.example.com:88

In Include directories I put only wp-content folder.

Don’t forget to enable the plugin!

So we my copy the directory wp-content to /var/www/cnd or simple create a link to it like this

cd /var/www/cdn ; ln -fs /var/www/blog/wp-content

Now we have working blog with static content served by cdn lighttpd daemon :-)

Other way to optimize your blog is to install php eAccelerator.

Install it and create eaccelerator.ini in /etc/php5/conf.d/ with those settings:


extension=”eaccelerator.so”
eaccelerator.shm_size=”16″
eaccelerator.cache_dir=”/var/cache/eaccelerator”
eaccelerator.enable=”1″
eaccelerator.optimizer=”1″
eaccelerator.check_mtime=”1″
eaccelerator.debug=”0″
eaccelerator.filter=”"
eaccelerator.shm_max=”0″
eaccelerator.shm_ttl=”0″
eaccelerator.shm_prune_period=”0″
eaccelerator.shm_only=”0″
eaccelerator.compress=”1″
eaccelerator.compress_level=”9″

After that
mkdir /var/cache/eaccelerator ; chmod 777 /var/cache/eaccelerator

Now restart the php daemon. That’s it ! 🙂