Home > Varnish, Webserver > Varnish 3.0 useful commands

Varnish 3.0 useful commands

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

varnishadm  debug.health | grep Happy | less
varnishadm  debug.health | 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: jackal.me"
varnishlog -c -m RxHeader:"Host: jackal.me" -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: jackal.me"

7) Search based on a custom VCL header,

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

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.http.host ~ "jackal.me" && !(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.http.host ~ "jackal.me"   && !(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(req.http.host ~ "jackal.me"){
    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.host ~ "jackal.me" && (req.http.referer && req.http.referer !~ "^http://jackal.me/")){
        error 403 "Hotlinking not allowed";


Categories: Varnish, Webserver
  1. May 28, 2015 at 11:52 pm

    Thank you!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: