Log in

View Full Version : load balancer/reverse proxy?


Mhatma
06-10-2007, 11:39 PM
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
06-14-2007, 04:52 AM
Anybody?

gabrielt
06-18-2007, 01:23 PM
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
09-17-2009, 08:09 PM
Thanks so much for posting this, even though it was over two years ago. This helped me greatly today.

Manoel J?nior
08-14-2010, 04:21 PM
Very thanks

obetyance
07-05-2012, 01:34 AM
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! :)