An example vmod for Varnish
Shell C
Latest commit fa6f6cf Jan 4, 2016 @lkarsten lkarsten Merge pull request #28 from adeelshahid/patch-1
install Pre-requisites
Failed to load latest commit information.
debian Determine necessary libraries automatically. Feb 11, 2015
src Formatting. Oct 4, 2015
.travis.yml Update travis-ci to work with Varnish 4.0. Oct 9, 2014
COPYING Clear up copyright statements. Mar 16, 2015
LICENSE Change license to public domain. Mar 3, 2015 Build man page from vcc file Sep 7, 2015
README.rst install Pre-requisites Dec 15, 2015 emit the right error also for older pkg-config versions which don't May 24, 2015 Inherit the prefix from Varnish and document installation directories Sep 29, 2015
rename-vmod-script was unable to cut text from command line only copy Dec 15, 2015
vmod-example.spec Use packaging name in docdir. Sep 15, 2015



Varnish Example Module

Date: 2015-03-03
Version: 1.0
Manual section:3


import example;


Example Varnish vmod demonstrating how to write an out-of-tree Varnish vmod.

Implements the traditional Hello World as a vmod.



hello(STRING S)
Return value
Returns "Hello, " prepended to S
set resp.http.hello = example.hello("World");


The source tree is based on autotools to configure the building, and does also have the necessary bits in place to do functional unit tests using the varnishtest tool.

Building requires the Varnish header files and uses pkg-config to find the necessary paths.


sudo apt-get install -y autotools-dev make automake libtool pkg-config libvarnishapi1 libvarnishapi-dev



If you have installed Varnish to a non-standard directory, call and configure with PKG_CONFIG_PATH pointing to the appropriate path. For example, when varnishd configure was called with --prefix=$PREFIX, use


Make targets:

  • make - builds the vmod.
  • make install - installs your vmod.
  • make check - runs the unit tests in src/tests/*.vtc
  • make distcheck - run check and prepare a tarball of the vmod.

Installation directories

By default, the vmod configure script installs the built vmod in the same directory as Varnish, determined via pkg-config(1). The vmod installation directory can be overridden by passing the VMOD_DIR variable to configure.

Other files like man-pages and documentation are installed in the locations determined by configure, which inherits its default --prefix setting from Varnish.


In your VCL you could then use this vmod along the following lines:

import example;

sub vcl_deliver {
        # This sets resp.http.hello to "Hello, World"
        set resp.http.hello = example.hello("World");


  • configure: error: Need varnish.m4 -- see README.rst

    Check if PKG_CONFIG_PATH has been set correctly before calling and configure

  • Incompatibilities with different Varnish Cache versions

    Make sure you build this vmod against its correspondent Varnish Cache version. For example, to build against Varnish Cache 4.0, this vmod must be built from branch 4.0.