Chris Rogers
Chris Rogers

Reputation: 1522

How to setup Varnish logging on Linux Alpine?

I'm aware Varnish logging isn't enabled by default and that it is enabled via varnishncsa, there are many articles online on how to set it up but not with Linux Alpine. I see configurations for it here. But not sure any logging service runs by default.

Any help would be much appreciated. Many thanks

Upvotes: 0

Views: 2116

Answers (1)

nickgryg
nickgryg

Reputation: 28593

To enable informative logs you need to start the following command:

/usr/bin/varnishncsa -q 'ReqURL ne "<url_which_should_be_not_logged>"' -F '%{Host}i %h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\" \"%{Varnish:hitmiss}x\"' -w /path/to/log_file

after varnishd is started:

/usr/sbin/varnishd -s malloc,128M -a :80 -f /etc/varnish/default.vcl

If we are talking about an Alpine in docker container, just create the following entrypoint.sh script:

#!/bin/bash

mkdir -p /var/lib/varnish/`hostname` && chown nobody /var/lib/varnish/`hostname`
/usr/sbin/varnishd -s malloc,128M -a :80 -f /etc/varnish/default.vcl

/usr/bin/varnishncsa -q 'ReqURL ne "<url_which_should_be_not_logged>"' -F '%{Host}i %h %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\" \"%{Varnish:hitmiss}x\"'

and place it to the end of the Dockerfile:

ENTRYPOINT ["/entrypoint.sh"]

Upvotes: 1

Related Questions