1

I'm running a setup with Nginx, FastCGI, APC, Memcache and Varnish to host a MediaWiki installation. I'm having some issues with recent changes showing up as coming from 127.0.0.1 in the case of anonymous users. I suspected the issue to be that Varnish doesn't pass on the user IP to Nginx properly, but I do have this in my vcl_recv:

# Set client IP
if (req.http.x-forwarded-for) {
    set req.http.X-Forwarded-For =
    req.http.X-Forwarded-For + ", " + client.ip;
} else {
    set req.http.X-Forwarded-For = client.ip;
}

Could anyone tell me what else I might need to verify that could cause this issue? Because I'm at a loss...

FHannes
  • 75
  • 9

2 Answers2

3

You must configure MediaWiki so that it will actually obey the X-Forwarded-For header. Without these settings, MediaWiki will ignore it.

(For historical reasons all of these configuration options refer to Squid...)

At a minimum, these lines must be in your LocalSettings.php:

$wgUseSquid = true;
$wgSquidServers = array('127.0.0.1'); # IP address of your varnish server
Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
0

The lines you describe from your configuration, set the X-Forwarded-For header to the client IP. However, you still need to tell your web server (Nginx) to check and use that value as the IP address.

The easiest way to do this is probably with Nginx's Real IP module. Firstly, check that Nginx has been built with the real IP module:

Run nginx -V and look for --with-http_realip_module

Then modify your Nginx config (usually /etc/nginx.conf), adding the following to the http section:

#Upstream server address (i.e. Varnish address)
set_real_ip_from 127.0.0.1;
real_ip_header X-Forwarded-For;

Restart Nginx and the IP address in all locations (logs, values passed to php, etc.) should now be derived from the X-Forwarded-For header.

cyberx86
  • 20,805
  • 1
  • 62
  • 81
  • I'm sorry, I should've mentioned that I already have this set up in my Nginx configuration. I've been over it to confirm, the real ip module is present and these lines are in my Nginx config. – FHannes Feb 09 '13 at 01:22