X-Forwarded-For and Apache 2.2.3

duja at torlen.net duja at torlen.net
Fri May 9 15:19:25 CEST 2008


Varnish is handling the X-Forwarded-For header automatically.

When you do like this:

remove req.http.X-Forwarded-For;

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

Varnish first removes the X-Forwarded-For header and then
adds a X-Forwarded-For header that is empty ("").

After that varnish uses the default vcl and appends the X-Forwarded-For header with the client ip. 

There for you get ", 123.456.789.101".

Just do like this:

remove req.http.X-Forwarded-For;

and Varnish should do the rest.

/ Erik

Original Message -----------------------
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
_______________________________________________
varnish-misc mailing list
varnish-misc at projects.linpro.no
http://projects.linpro.no/mailman/listinfo/varnish-misc




More information about the varnish-misc mailing list