Restore original remote_ip algorithm.

We incorrectly were using the first address, rather than the last one.

Fixes #7979

/cc @indirect @gazay