Select Page

Varnish is a reverse proxy designed to speed up your PHP apps. A good introduction can be read on IBM’s site and on the PHP Manual.

 

Installation:

curl http://repo.varnish-cache.org/debian/GPG-key.txt | sudo apt-key add –

echo “deb http://repo.varnish-cache.org/ubuntu/ precise varnish-3.0” | sudo tee -a /etc/apt/sources.listdeb http://repo.varnish-cache.org/ubuntu/ precise varnish-3.0

then update apt by running:

sudo apt-get update

install Varnish by:

sudo apt-get install varnish

Next we need to edit the default Varnish config:

sudo nano /etc/varnish/default.vcl

Then replace

“# backend default {

# .host = “127.0.0.1”;

# .port = “8080”;

# }”

With

backend default {

.host = “127.0.0.1”;

.port = “8080”;

}

 

Edit the ports.conf file

sudo nano ports.conf

and change the port setting from “Port 80” to “Port 8080”, and restart apache.

sudo service apache2 restart

You may also have to change “Listen 80” to “Listen 8080” if it exists.

 

Now open the Varnish default.vcl and change the port of the default backend to 8080.

Edit the Vhosts file in sites-enabled:

sudo nano my-virtual-hosts-site
to be on 8080

pkill varnishd

sudo varnishd -f /etc/varnish/default.vcl -s malloc,1G -T 127.0.0.1:2000

Check logs with : Varnishlog

Should look like:

12 TxProtocol   c HTTP/1.1
12 TxStatus     c 500
12 TxResponse   c Internal Server Error
12 TxHeader     c Server: Apache/2.2.22 (Ubuntu)
12 TxHeader     c X-Powered-By: PHP/5.3.10-1ubuntu3.4
12 TxHeader     c cache-control: no-cache, max-age=1
12 TxHeader     c Expires: Mon, 21 Jan 2013 10:26:48 GMT
12 TxHeader     c Vary: Accept-Encoding
12 TxHeader     c Content-Encoding: gzip
12 TxHeader     c Content-Type: text/html; charset=UTF-8
12 TxHeader     c Content-Length: 8094
12 TxHeader     c Accept-Ranges: bytes
12 TxHeader     c Date: Mon, 21 Jan 2013 10:26:50 GMT
12 TxHeader     c X-Varnish: 1823340195

varnishtop -i rxurl

will show you what URLs are being asked for by the client. 

varnishtop -i txurl

will show you what your backend is being asked the most. 

varnishtop -i RxHeader -I Accept-Encoding

will show the most popular Accept-Encoding header the client are sending you.

%d bloggers like this: