X-Forwarded-For and Apache 2.2.3

Lars Erik Dangvard Jensen lars at dcmediahosting.com
Wed May 7 15:41:44 CEST 2008


Hello list

I've been struggling a little with varnish 1.1.2 and apache 2.2.3 and  
the X-Forwarded-For header.

My problem is that the X-Forwarded-For header keeps returning af comma  
separated list of the same IP like this in the apache log:

123.456.789.101, 123.456.789.101 - - [07/May/2008:15:27:03 +0200]  
"GET ....etc.

The format I wish I could have is:

123.456.789.101 - - [07/May/2008:15:27:03 +0200] "GET ....etc.

Without , 123.456.789.101 in the log line.

I've used this in my vcl to remove the port number of the first IP in  
X-Forwarded-For header:
remove req.http.X-Forwarded-For;
set req.http.X-Forwarded-For = regsub(client.ip, ":.*$", "");

If I do like this:

set req.http.X-Forwarded-For = "";

The log looks like:

, 123.456.789.101 - - [07/May/2008:15:27:03 +0200] "GET ....etc.

I'm not able to figure out how to remove , 123.456.789.101 from the  
log line. Even though I set the X-Forwarded-For header to nothing  
through varnish vcl the , 123.456.789.101 is still showing?

My apache 2.2.3 logformat is this:
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\"  
\"%{User-Agent}i\"" varnishlog

Is it because I use varnish and apache on the same server?

I'm using Centos 5.1.

Any help is appreciated :)

/Lars



More information about the varnish-misc mailing list