Configure Varnish

From Fabelier
Jump to: navigation, search

Here is a little example about configuring Varnish in the fabelier's dev server to host a project. If any question, ask Julien (julien at palard point fr)

  • First, edit the file /etc/varnish/default.vcl (If you use emacs, M-x c-mode and enjoy syntax highlighting as vcl ils inspired by c)
  • Add a backend for your project, here it's "YourStuff" :
 # YourName : YourComment...
 backend YourStuff
   .host = "";
   .port = "8090";
  • In the `sub vcl_recv`, add a condition that match your url (checking for req.url) / host (checking for / whatever. If you *haven't* query yet (on your browser or other..) your future sub domain of "mystuff", you can attribute it by yourself like that :
 if ( == "")
     set req.backend = YourStuff;
  • If necessary, fine tune the TTL for your responses, default is 10mn :
 if (req.backend == YourStuff)
     set beresp.ttl = 300s;
  • Reload varnish (never restart, in case there is a bug in your configuration file !) :
 $ /etc/init.d/varnish reload
 Reloading HTTP accelerator: varnishdCommand failed with error code 106
  • Damned, there is a bug in varnish's default.vcl, that's nice there is a command to check it:
 $ /usr/sbin/varnishd -Cf /etc/varnish/default.vcl
 Message from VCC-compiler:
 Syntax error at
 (input Line 29 Pos 19)
    if ( ==")

Fix it, reload, enjoy !

File too big to be handled by Varnish ? a quick fix is to add :

if (req.url ~ "\.zip$")
       return (pipe);
Personal tools