I have a set of Nginx servers behind an Amazon ELB load balancer. I am using set_real_ip (from the HttpRealIpModule) so that I can access the originating client IP address on these servers (for passing through to php-fpm and for use in the HttpGeoIPModule).
It seems that set_real_ip_from
in the nginx configuration can only accept an IP address. However, with regard to ELB machines Amazon say:
Note: Because the set of IP addresses associated with a LoadBalancer can change over time, you should never create an "A" record with any specific IP address. If you want to use a friendly DNS name for your LoadBalancer instead of the name generated by the Elastic Load Balancing service, you should create a CNAME record for the LoadBalancer DNS name, or use Amazon Route 53 to create a hosted zone. For more information, see the Using Domain Names With Elastic Load Balancing
But if I need to input an IP address I can't use a CNAME (either amazon's or my own). Is there a solution to this problem?
Answer
If you can guarantee that all requests will be coming from ELB (I'm not familiar with it), you could try:
real_ip_header X-Forwarded-For;
set_real_ip_from 0.0.0.0/0;
That should tell nginx to trust an X-Forwarded-For header from anyone. The downside is that if anyone directly accesses your server, they would be able to spoof an X-Forwarded-For header and nginx would use the wrong client ip address.
Comments
Post a Comment