Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have set up varnish as a proxy to redirect HTTP-request to backend-servers running apache. I would like to have the clients IP-addresses in my apache logs instead of the varnish server IP-address. Here is my varnish configuration file:

backend $my_backend {
    .host = "";
    .port = "80";
sub vcl_recv {
} else if ( == "$my_domain_name") {
    set req.backend = $my_backend;
    if (req.request == "POST") {
        if (req.http.X-Forwarded-For) {
          set req.http.X-Real-Forwarded-For = req.http.X-Forwarded-For ", " regsub(client.ip, ":.*", "");
          unset req.http.X-Forwarded-For;
       } else {
          # Simply use the client IP
          set req.http.X-Real-Forwarded-For = regsub(client.ip, ":.*", "");

On the backend apache config file I have this

RPAFenable On
RPAFsethostname On
RPAFproxy_ips $varnish_proxy_ip
RPAFheader X-Real-IP

The problem is that the instruction RPAFheader is not recognized on Debian6:

root@$hostname:~# apache2ctl configtest
Invalid command 'RPAFheader', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.

Have anyone set up mod_rpaf on debian to give me a hand on this troublemod_rpaf

Thank you very much for your help!

share|improve this question
up vote 3 down vote accepted

Ok, I will answer my own question to help people who may have the same problem:

First add the following lines into varnish configuration file (default.vcl)

sub vcl_recv {
   if ( == "") {
       set = "";
       set req.backend = myBackend;
       # Compatiblity with Apache log
       remove req.http.X-Forwarded-For;
       set req.http.X-Forwarded-For = client.ip;
       # No cache for POST requests
       if (req.request == "POST") {

Then add personalized logs format for apache while configuring your vhost

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" varnishcombined
 CustomLog      ${APACHE_LOG_DIR}/access.log varnishcombined

That's it!

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.