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 http://repo.varnish-cache.org/redhat/varnish-3.0/el5/noarch/varnish-release-3.0-1.el5.centos.noarch.rpm
yum install varnish

For CentOS 6 / RHEL 6:
rpm --nosignature -i http://repo.varnish-cache.org/redhat/varnish-3.0/el6/noarch/varnish-release-3.0-1.el6.noarch.rpm
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 123.123.123.123 with your Apache server's IP address)


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

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

Listen 80

to 

Listen 8080

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

Include /etc/httpd/conf/ips.conf

#
#
<VirtualHost 123.123.123.123:80>

to

#Include /etc/httpd/conf/ips.conf
LogFormat "%O \"%r\"" homedir
NameVirtualHost 127.0.0.1:8080
NameVirtualHost 123.123.123.123:8080
NameVirtualHost 123.123.123.123:443
#
#
<VirtualHost 127.0.0.1:8080 123.123.123.123:8080>

Again, remember to replace 123.123.123.123 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|>

to 

<VirtualHost 127.0.0.1:8080 |IP|:8080 |MULTI_IP|>

8. We need reverse proxy module for Apache

wget http://www.stderr.net/apache/rpaf/download/mod_rpaf-0.6.tar.gz
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
RPAFproxy_ips 127.0.0.1
RPAFheader X-Forwarded-For
</IfModule>

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...