blah blah blah is here! blah blah » Close

up0down
link

It seems the regular method of getting a visitors ipaddress doesn't work on rackspace cloud sites.

I track IP on user interaction with the site (questions/answers/comments/voting/etc) and just looking at the db tells me everyone is on the same IP!

It seems the IP address is coming from the load balancer setup (or something related to it).

Anyone know how to get the IP when hosted on a cloud service? (rackspace cloud sites specifically)

last answered 2 years ago

2 answers

up0down
link

It turns out with Rackspace cloud sites (and other cloud providers I'm sure) you have to do things a little differently because of load balancers.

Calling REMOTE_ADDR (or Request.UserHostAddress) as I was doing will not work.

So the solution is to do the following:

if(Request.IsSecureConnection)

ipAddress = Convert.ToString(Request.ServerVariables["HTTP_X_FORWARDED_FOR"]);
else if (null != Request.ServerVariables["HTTP_X_CLUSTER_CLIENT_IP"])
ipAddress = Convert.ToString(Request.ServerVariables["HTTP_X_CLUSTER_CLIENT_IP"]);


I added in the server variable key for SSL connections.

Reference: http://help.mosso.com/article.php?id=180

Rick_A
761

That's interesting how they implement SSL across the cluster.

up0down
link

any time you have a proxy introduced into the mix the IP address you will have will be that of the proxy. Proxies *should* always include the forwarded_for header, but some out there do not (your host will, but there could also be one that is being used to view the site too, so it's all an approximation).

Feedback