Skip to main content

Debugging and Changing Varnish in the live environment

Back-end Development
Drupal

Want to change or debug Varnish on a live server?  Making changes to the default.vcl (or whatever configuration is being used) on a live varnish server is risky business, and you shouldn't do it.  Especially if you are a DevOps guy that doesn't spend all his time configuring servers.

It is easy enough to spin up a new varnish server alongside your live one to test with.

You will want to copy your VCL file being used like so.

sudo cp /etc/varnish/default.vcl /etc/varnish/debug.vcl

Your new debugging instance will refer to this VCL file for configuration.  This is the file you will change and test with.

To start up a new instance using this copied configuration file issue the following command.

sudo varnishd -F -f /etc/varnish/debug.vcl -u varnish -g varnish -a :81 -n test_instance -s file,/tmp/varnish_storage.bin,10M &

The ending & is used to run the process in the background in case you are not familiar with that syntax.

This will create a new server instance on port 81. Obviously you can use another port if you would prefer.

Bonus Hint:

You can see your active varnish processes by issuing the command:

ps aux | grep varnishd

To kill the debug instance (to restart, for example) you need to send your kill command to the parent process.  The one owned by root.  This will also terminate the child process owned by varnish

If you plan to be spending some time messing with varnish configuration you might want to consider also passing along another parameter to your varnishd startup command.  The -T option is used to specify an admin port.  If you do this you can use the admin for managing the cache, stopping, and starting, etc.

varnishadm -n test_instance

If you do not include this option, and try to use the varnish admin utility you will receive an error telling you to use the -T option.

Additional Resources