Announcement

Collapse
No announcement yet.

Varnish 3.0 Useful Commands

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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

    Code:
    varnishadm debug.health | grep Happy | less
    varnishadm debug.health | grep -i sick

    2) Log all incoming POST requests for 10 minutes,

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

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

    Code:
    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,

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

    5) Hit to miss ratio based on IP address,

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

    6) Find details of 503 error to a domain,

    Code:
    varnishlog -c -m TxStatus:503 -m RxHeader:"Host: jackal.me"

    7) Search based on a custom VCL header,

    Code:
    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),

    Code:
    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("unsettingheader");
      return(deliver);
    }
    b) In VCL recv file add,

    Code:
    if(req.http.host ~ "jackal.me" && !(req.url ~ "wp-admin")){
      unset req.http.etag;
      unset req.http.Cookie;
      return(lookup);
    }
    c) Reload varnish

    Code:
    service varnish reload

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

    Code:
    Header add X-Varnish-Control "disabled"

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

    Code:
    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,

    Code:
    if(req.http.host ~ "jackal.me" && (req.http.referer && req.http.referer !~ "^http://jackal.me/")){
    error 403 "Hotlinking not allowed";
    }
Working...
X