Setting up Varnish with DirectAdmin

This article explains the steps taken to set up Varnish on CentOS running DirectAdmin control panel. This how-to assumes that you already have DirectAdmin installed.

1. First you would need to install some dependencies:
yum -y install automake autoconf libtool ncurses-devel libxslt groff pcre-devel pkgconfig

2. Install Varnish

For CentOS 5 / RHEL 5:
rpm --nosignature -i
yum install varnish

For CentOS 6 / RHEL 6:
rpm --nosignature -i
yum install varnish

3. Assuming Apache will be running on port 8080, we need to make the following changes to /etc/varnish/default.vcl (Replace with your Apache server's IP address)

backend default { .host = ""; .port = "8080"; }

4. Now open /etc/httpd/conf/httpd.conf and change:

Listen 80


Listen 8080

5. Open /etc/httpd/conf/extra/httpd-vhosts.conf and change:

Include /etc/httpd/conf/ips.conf



#Include /etc/httpd/conf/ips.conf
LogFormat "%O \"%r\"" homedir

Again, remember to replace with your Apache server's IP address.

6. We need to copy DirectAdmin templates to a safe location before editing

cp -p /usr/local/directadmin/data/templates/virtual_host2.conf  /usr/local/directadmin/data/templates/custom/virtual_host2.conf
cp -p /usr/local/directadmin/data/templates/virtual_host2_sub.conf  /usr/local/directadmin/data/templates/custom/virtual_host2_sub.conf
cp -p  /usr/local/directadmin/data/templates/redirect_virtual_host.conf  /usr/local/directadmin/data/templates/custom/redirect_virtual_host.conf

7. Open each of the files in /usr/local/directadmin/data/templates/custom and change:

<VirtualHost |IP|:80 |MULTI_IP|>


<VirtualHost |IP|:8080 |MULTI_IP|>

8. We need reverse proxy module for Apache

tar xzf mod_rpaf-0.6.tar.gz
cd mod_rpaf-0.6
apxs -cia mod_rpaf-2.0.c

9. Once mod_rpaf is installed, we need to connect it to Apache. Open /etc/httpd/conf/extra/httpd-includes.conf and the module configuration:

<IfModule mod_rpaf-2.0.c>
RPAFenable On
RPAFsethostname On
RPAFheader X-Forwarded-For

10. Ask DirectAdmin to rewrite Apache configuration templates

echo "action=rewrite&value=httpd" >> /usr/local/directadmin/data/task.queue

11. Finally restart Apache and start Varnish

/etc/init.d/httpd restart
/etc/init.d/varnishd start

You're all set. You now have a fully functional Varnish+Apache running on a DirectAdmin server. 

Was this answer helpful?

Also Read

Changing PHP Version

DirectAdmin can support up to two PHP versions at a time and you can select a different PHP...

DirectAdmin: nginx/Apache

It is proven that nginx is much faster than Apache when dealing with static files. If you wish to...