Problem with X-Forwarded-For in Varnish 3.0

6 posts / 0 new
Last post
Nemesis11
Problem with X-Forwarded-For in Varnish 3.0

Hi,

We are trying to implement Varnish 3.0 and almost everything went well, but we have a problema with X-Forwarded-For

Our web site deppends on the real ip of the user accessing it. The site is in php 5.3 and we used something like the following code to view the real ip:

<?php

echo ' Client IP: ';

if ( isset($_SERVER["REMOTE_ADDR"]) )    {

    echo '' . $_SERVER["REMOTE_ADDR"] . ' ';

}

?>

That gave us something like "Client IP: 85.87.212.83"

With Varnish we altered REMOTE_ADDR to HTTP_X_FORWARDED_FOR in php.

We configured varnish to give us a response for HTTP_X_FORWARDED_FOR. In the VCL we have:

 

sub vcl_recv

{

remove req.http.X-Forwarded-For;

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

}

 

But when in php, using the some code, but looking for HTTP_X_FORWARDED_FOR the response is empty. We get this:

"Client IP:"

The response is empty and we need to know the real ip address from the client. We tried various things, without success.

Can someone help us?

cerw

 I have the same problem , need to get REMOTE_ADDR working under php 5.3 when using Varnish..

david
david's picture

This works for me…

sub vcl_recv {
   set req.http.X-Forwarded-For = client.ip;
}

 

-david

saulo

same problem, php 5.2 varnish 3.02

saulo

My problem was solved with rpaf apache module.

very_random_man

I used the RPAF module to solve this but then it stopped working about an hour later for no apparent reason. It just stopped adding the X-Forwarded-For header.

I added it in the VCL instead which is better due to

a) no module compiling or installing httpd-devel on production servers.

b) more transferable between servers as it'll work wherever Varnish is installed

c) less things to go wrong!