tiistai 8. lokakuuta 2013

Varnish - a web application accelerator (How To Setup Varnish On Linux)

"Varnish is a web application accelerator. You install it in front of your web application and it will speed it up significantly." Varnish kinda does a static copy of your web page and loads it to ram memory. Static web page is a lot faster to serve than page with dynamic content as I demonstrated in the post below.

Prerequisites:
Apache2
Dynamic and static page for testing for example Wordpress

Step one. Install Varnish
sudo apt-get install varnish

Step two. Configure Varnish
sudoedit /etc/default/varnish

Look for lines that are not commented in "Alternative 2" and change DAEMON_OPTS to port 80.


Save that file and exit after two port changes. You can check if default.vcl file is set correctly. Default port should be 8080, if not change it to 8080.

sudoedit /etc/varnish/default.vcl


Step three. Configure Apache.

sudoedit /etc/apache2/ports.conf

We told Varnish to listen port 8080 but Apache default is set to 80 so we have to change that. Change to both virtual and listen 8080.


And as always after making changes, kick the demons.

sudo service apache2 restart
sudo service varnish restart


Now open your browser and type localhost to see if your setup is working correctly. If not you can try changing all * marks from setting files to 127.0.0.1

Testing Varnish

First stop your Varnish
sudo service varnish stop
Apache benchmark your Wordpress 

ab -n100 -c100 http://localhost:8080/~shnigi/wordpress/



As you can see it is not very fast. Then start Varnish again
sudo service varnish restart
And do the same test again but not in the port 8080
ab -n100 -c100 http://localhost/~shnigi/wordpress/


And as you can see Varnish + Apache is a lot faster than without Varnish! Static page is an advantage. Remember to check that commenting and other dynamic things work normally. 

Source: https://www.digitalocean.com/community/articles/how-to-install-and-configure-varnish-with-apache-on-ubuntu-12-04--3

INFO: Varnish doesn't work on RaspberryPi out of the box. If you somehow mess your Varnish setup and want to return Apache to port 80 you may need to check what program is blocking port 80. Probably Varnish at this point. Use: sudo netstat -tulpn| grep :80 to find out what is blocking that port and then kill it: pkill varnish

Ei kommentteja:

Lähetä kommentti