pup icon indicating copy to clipboard operation
pup copied to clipboard

cluster - remoteAddr.hostname is always 127.0.0.1

Open Ewok167 opened this issue 1 year ago • 1 comments

How to get client IP? This only happens when using the cluster common port. Deno.serve

Ewok167 avatar Dec 08 '24 13:12 Ewok167

See the info at https://pup.56k.guru/usage/scaling/#built-in-vs-external-load-balancer

The built-in load balancer (which is enabled when you supply the commonPort option) uses a very simple TCP proxy mechanism (https://github.com/Hexagon/pup/blob/main/lib/core/loadbalancer.ts) that doesn't allow forwarding the IP the way you want.

If you use something like NGINX as an HTTP proxy to the individual cluster ports (startPort...), NGINX will supply you with the X-Forwarded-For header, which will contain the actual client IP.

A solution for this within Pup would be to add a HTTP-specific load balancer, which provide the X-Forwarded-For header.

Let's leave this issue open if anyone is up for a PR

Hexagon avatar Dec 08 '24 20:12 Hexagon