Ask Your Question

log setenvif question

asked 2015-05-18 13:11:29 -0600

RHuffman gravatar image

In our current Apache configurations, we're capturing the value of the X-Forwarded-for header (if present), and logging differently based on that (among other reasons, to cut down on clutter, since our internal monitoring tools/health checks do not pass through our load balancer, and therefore do not get an X-Forwarded-for header attached).

The basic gist of the Apache logging configuration:

  LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
  LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" forwarded
  SetEnvIf X-Forwarded-For "^.+" forwarded
  CustomLog "${APACHE_LOG_DIR}/access.log" combined env=!forwarded
  CustomLog "${APACHE_LOG_DIR}/access.log" forwarded env=forwarded
  ErrorLog ${APACHE_LOG_DIR}/error.log

I can see where to enable the setenvif module and the log format:

  class { 'apache':
    default_mods => false,
    default_confd_files => false,
    log_formats => {
      combined  => '%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"',
      forwarded => '"%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"',


  apache::vhost { '':
    docroot   => '/nas/static/',
    setenv    => ['X-Forwarded-For "^.+" forwarded'],

But I don't know how to tell puppet to write the conditional, or whether it's even possible using the puppet language.

Any help would be appreciated.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-09-03 09:17:24 -0600

SimonH gravatar image

setenvif is available in the puppetlabs-apache module (I guess it's possible it wasn't when you asked the question).

Both setenv and setenvif take a string with the full options, so something like:

apache::vhost { '':
    docroot   => '/var/www/html',
    setenv    => ['DATA_ROOT /var/data'],
    setenvif  => [ 'X-Forwarded-For "^.+" forwarded' ]
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-05-18 13:11:29 -0600

Seen: 1,212 times

Last updated: Sep 03 '15