I have been struggling with this problem for quite some time until today I found this post:
http://ocaoimh.ie/2011/08/09/speed-up-wordpress-with-apache-and-varnish/
The solution proposed does not imply hacking the code:
Create a file called, for instance, /usr/share/php/real-ip.php with the following contents:
<?php
if ( isset( $_SERVER[ "HTTP_X_FORWARDED_FOR" ] ) ) {
$_SERVER[ 'REMOTE_ADDR' ] = $_SERVER[ "HTTP_X_FORWARDED_FOR" ];
}
?>
Then add it to your php.ini file, search for:
auto_prepend_file =
And replace with:
auto_prepend_file = /usr/share/php/real-ip.php
It worked like a charm for me!