PDA

View Full Version : load balancer/reverse proxy?


Mhatma
11 Jun 2007, 01:39
Hi, I help maintain the servers for a large vBulletin forum (usually 500-1000 concurrent users online), we currently have 3 servers (1 sql, 2 web servers running lighttpd) and recently had a hardware load balancer installed.

The problem is the load balancer acts as a reverse proxy, and vBulletin/the webservers see all requests as coming from the load balancers ip rather than the users ip - which means vBulletin sees everyone who isnt logged in already as the same user which means it's incredibly hard to login (due to people getting their password wrong etc), search, and keep track of users from their actual IP's.

According to our datacenter the original source IP is sent to the webservers in the X-forwarded-for header, is there anyway to get vBulletin to use this header instead of the normal one it's using?

Mhatma
14 Jun 2007, 06:52
Anybody?

gabrielt
18 Jun 2007, 15:23
Hi there,

I use a software load balancing but the idea is the same.

You have to edit class_core.php

and change from:

/**
* Fetches the IP address of the current visitor
*
* @return string
*/
function fetch_ip()
{
return $_SERVER['REMOTE_ADDR'];
}


To:

/**
* Fetches the IP address of the current visitor
*
* @return string
*/
function fetch_ip()
{
return (getenv(HTTP_X_FORWARDED_FOR))
? getenv(HTTP_X_FORWARDED_FOR)
: getenv(REMOTE_ADDR);
}


Also don't forget to edit your lighttpd configuration (lighttpd.conf) in order to log the user IP address. At this file you need to replace %h with %{X-Forwarded-For}i on the accesslog.format line. Example:

From:
accesslog.format = "%h

To:
accesslog.format = "%{X-Forwarded-For}i

Cheers,
Gabriel.

mrklewis
17 Sep 2009, 22:09
Thanks so much for posting this, even though it was over two years ago. This helped me greatly today.

Manoel Júnior
14 Aug 2010, 18:21
Very thanks

obetyance
05 Jul 2012, 03:34
Also don't forget to edit your lighttpd configuration (lighttpd.conf) in order to log the user IP address. At this file you need to replace %h with %{X-Forwarded-For}i on the accesslog.format line. Example:

From:
accesslog.format = "%h

To:
accesslog.format = "%{X-Forwarded-For}i

Where can we find this "LIGHTTPD.CONF"?

Thanks! :)