Varnish is a reverse proxy
working with apache, with all traffic go thriugh Varnish cache first
if cache missed, Varnish will be the one to grab content from Apache
It is because Apache ignore file types
For example, deliver a jpg by Apache will load mod_php into RAM
the same applies to CSS and JS files
This will cause massive RAM footage
And Varnish cache help greatly helped these static files with less resources drain
and improve overall performance
My target is install Varnish with minimum downtime
Remember to backup the config files before continue
Install Varnish
curl http://repo.varnish-cache.org/debian/GPG-key.txt | sudo apt-key add -
echo "deb http://repo.varnish-cache.org/ubuntu/ lucid varnish-3.0" | sudo tee -a /etc/apt/sources.list
sudo apt-get update
sudo apt-get install varnish
Default Varnish will connect to localhost port 8080 for Apache
So we open port 8080 on Apache:
sudo vim /etc/apache2/ports.conf
NameVirtualHost *:80
NameVirtualHost *:8080
Listen 80
Listen 8080
To minimize downtime, apache will open both 80 and 8080 for the moment
80 for normal operations
8080 For testing out connection with Varnish
VirtualHost settings
sudo vim /etc/apache2/sites-avaiable/default
<VirtualHost *:80 *:8080>
restart Apache
sudo service apache2 restart
open a browser and go to http://localhost:8080/ test Apache port 8080
Varnish will use 256M RAM by default, change to 64M:
sudo vim /etc/default/varnish
DAEMON_OPTS="-a :6081 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,64m"
sudo /etc/init.d/varnish restart
You can see Varnish use port 6081 as default
open http://localhost:6081/ and test Varnish
Using chrome's network inspector you can see under “Response Header" "Via 1.1 varnish" as identicator
After testing success, time to use Varnish for real thing
Modify Apache:
sudo vim /etc/apache2/ports.conf
#NameVirtualHost *:80
NameVirtualHost *:8080
#Listen 80
Listen 8080
Modify Varnish:
DAEMON_OPTS="-a :80 \
-T localhost:6082 \
-f /etc/varnish/default.vcl \
-S /etc/varnish/secret \
-s malloc,64m"
restart Apache, Varnish at the same time
sudo service apache2 restart;sudo /etc/init.d/varnish restart