I have a caddy file which manage multiple projects : a few PHP projects (using file_server instruction) and nodejs project dynamically (using reverse_proxy instruction)
On my PHP project when I read the request headers, x_forwarded_for is filled with the client IP address. But on my node project, it is filled with the server IP address
2. Error messages and/or full log output:
Wrong IP
Header in node (I’ve limited to the interesting ones):
Caddy already passes the X-Forwarded-For header by default.
Whatever is serving your node program will have to be configured to trust caddy as a proxy.
If you have a caddy instance downstream at localhost:3001 serving your node program, then the way to achieve this is to add a global block in the downstream Caddyfile like this
But got the same result, X-Forwarded-For is my server IP, even if it’s in trusted_proxies now.
There is this documentation on pm2: PM2 - Production Setup with Nginx.
Seems with nginx they pass the header information with proxy_set_header, but not sure if I have to do something equivalent with caddy.
This doesn’t make sense – you should trust IP addresses of servers in front of Caddy. If you don’t have another proxy in front of Caddy, you should not add this.
Anyway, as @victor said, Caddy does the right thing by default. If your app isn’t receiving the correct X-Forwarded-For value, then something between Caddy and your app is the problem (i.e. pm2), and not Caddy itself. So you should get help from them.