Archive for the ‘Webserver’ Category

Varnish 3.0 useful commands

May 28, 2015 1 comment

Some useful notes and commands which will be useful for administering varnish 3.0 web caching server,
1) Find healthy and sick backends

varnishadm | grep Happy | less
varnishadm | grep -i sick 

2) Log all incoming POST requests for 10 minutes,

timeout 10 varnishlog -c -m RxRequest:POST > /tmp/POSTlog

3) Search varnish live log based on specific domain and URL,

varnishlog -c -m RxHeader:"Host:"
varnishlog -c -m RxHeader:"Host:" -m RxURL:"/wp-admin/post-new.php"

4) Get list of IPs from which POST requests are received for wp-login.php,

varnishncsa -F %h -m RxRequest:POST -m RxUrl:wp-login.php

5) Hit to miss ratio based on IP address,

varnishncsa  -F  "%h %s %{Varnish:hitmiss}x" 

6) Find details of 503 error to a domain,

varnishlog -c -m TxStatus:503 -m RxHeader:"Host:"

7) Search based on a custom VCL header,

varnishlog -c -m VCL_Log:"X-JACK-SEC: wpblock" -m RxHeader:"Host:"

8) Manually PURGE cache of a domain from varnish server,

read -p "Domain: " DOMAIN && read -p "URL: " URL && echo -e 'PURGE ${URL} HTTP/1.1\nHost: ${DOMAIN}\n\n' | nc localhost 80

9) Force caching a domain in varnish 3.0,
a) In VCL fetch file add(exclude requests for wp-admin),

if(( ~ "" && !(req.url ~ "wp-admin"))) {
        unset beresp.http.set-cookie;
        unset beresp.http.Cache-Control;
        unset beresp.http.Pragma;
        unset beresp.http.X-Powered-By;
        std.log("unsetting set header");

b) In VCL recv file add,

if( ~ ""   && !(req.url ~ "wp-admin")){
        unset req.http.etag;
        unset req.http.Cookie;


c) Reload varnish

service varnish reload

10) Disable caching for a domain in backend. For this purpose add the following line in ‘.htaccess’,

Header add X-Varnish-Control "disabled"

11) Block a website. In sub-function fetch and recv add,

if( ~ ""){
    error 403 "Website suspended. Contact support for more information";

12) Enable hot link protection. Add the following in RECV function and reload varnish,

if( ~ "" && (req.http.referer && req.http.referer !~ "^")){
        error 403 "Hotlinking not allowed";


Categories: Varnish, Webserver