Request IP in Phoenix on a Unix socket behind rev-proxy

After walking over largely uncharted terrain for some good time I arrived at the point where I have a phoenix application and all its dependencies containerised in a docker container, exposing unix socket, to which the rev-proxy (nginx) connects from outside the container. All nice, except that I have no idea how to get the original request IP recognised by the application. When configuring Phoenix Endpoint to use unix socket, the configuration as described here is {:local, path} tuple and the application “sees” the IP as local rather than any address. Nginx can easily be configured to add some headers with orginal IP but is there a way to pass that information down to Phoenix application?

The remote_ip plug is a good place to start, assuming you’ve got nginx sending the right headers.

IIRC it’s not built-in because it’s only safe to trust those headers behind a correctly-configured proxy.


Yes, this works - TNX!