For security reasons, sometimes it is needed to block users by IP. In my case, I would like to manage the IP blacklist in a (SQL) database. I guess I can handle the filter part based on Action Composition but for that I need the user's IP.
So, how can I get the user's IP?
PS : The application is running behind a nginx proxy.
If your Play! app is behind nginx (or any other reverse proxy),
request.remoteAddress()
will only return the IP address of your nginx host. In order to retrieve the real IP of the client you should have the following in your proxy_pass configuration of nginx:This will add the client IP as parameter to the header
doc: Nginx
And then within your Play! app you would retrieve it like this:
doc: Java, Scala
It's now possible with Play 2.0.2+ : RequestHeader.remoteAddress()
Java :
Scala :