0

It appears my Amazon Elastic Load Balancer is allocating traffic to EC2's, but without their IP addresses?

Is this usual behaviour? It's incredibly annoying. I.e. ELB CName is on my domain name DNS, I hit the domain and access log has the IP address of the ELB, not the visitor.

1

2 Answers 2

2

If you're running ELB in HTTP mode, it adds some HTTP headers to the request sent to the EC2 instances, amongst which is the X-Forwarded-For header which will contain the IP address of the client.

X-Forwarded-For: 203.0.113.7

Note that this header can potentially contain more than one IP if other load balancers or proxies handled the request. In this case you want to extract the first IP listed.

X-Forwarded-For: 203.0.113.7, 10.12.33.44, 10.73.23.88
2

Since the link in your comment is broken, here's how to log visitors' IP addresses:

In httpd.conf, create a new log format:

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" combined-elb

Then to use it:

CustomLog logs/access_log combined-elb

It's that simple.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .