Learn Varnish on Arch Linux, Nginx and Django
Varnish Cache is a web application accelerator also known as a caching HTTP reverse proxy. You install it in front of any server that speaks HTTP and configure it to cache the contents.
Install
Generally speaking, you should restart nginx then varnish in this order when making changes.
Set port to 8080 in nginx config
Set the backend port to 8080 in VCL config. It’s 8080 by default
All incoming requests will hit Varnish first. If it is unable to serve up a cached version, it will use the backend specified (you can define multiple backends). By default, we use nginx so nginx gets hit which in turn calls uwsgi.
https://www.varnish-cache.org/trac/wiki/VCLExampleCacheCookies
http://stackoverflow.com/questions/12034242/is-varnish-compatible-with-django-csrf-protection
You also have to remove the sssionid and csrftoken set in the cookies. The VCL file below shows you how
The VCL file is the place where you control the rules.
Some basic settings
The service file in /etc/systemd/system/varnish.service be defaults listens on port 80. To change the allocated ram, change 64M to whatever you wish.
To check config file. If everything is ok, there will be a printout
To ban a particular page (clear the cache for the page)
What you don’t see here is the CPU utilization. Nginx uses a little bit more but not significantly.