Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Framework - Retrieve the client's IP when using TCP load balancing

Use case: a Play application behind Amazon ELB which is configured for TCP load balancing.

Amazon ELB provides the client's connection information via Proxy Protocol 1.

How to retrieve this information in Play?

like image 608
tokarev Avatar asked Sep 22 '14 15:09

tokarev


1 Answers

If you have turned on proxy protocol support, it adds haproxy's proprietary proxy protocol header as the first thing sent in the TCP request. Effectively, it adds the following line before the http request:

PROXY TCP4 192.168.0.1 192.168.0.11 56324 443

This is not valid HTTP, so Play does not support it, if Play receives a request like this, it will simply return an error.

What you can do is install a proxy on your EC2 node that does support proxy protocol, and then have that add the proxy protocol ip address into the X-Forwarded-For header to the Play app. Instructions on how to configure nginx to support proxy protocol in this way can be found here:

https://chrislea.com/2014/03/20/using-proxy-protocol-nginx/

like image 134
James Roper Avatar answered Sep 17 '22 19:09

James Roper