With reverse_proxy
directive,
Is there a way to add the IP address from the requester into HTTP body before it get send to upstream?
Or if I can’t do that,
How do you at least get the IP address to be included into query string instead of body?
With reverse_proxy
directive,
Is there a way to add the IP address from the requester into HTTP body before it get send to upstream?
Or if I can’t do that,
How do you at least get the IP address to be included into query string instead of body?
Could you clarify why you need this? The client IP is added to the X-Forwarded-For header
I’m using third-party analytics,
And to be able to determine user location,
they need the client IP address sent to them in HTTP body (among other information is stored here).
If I just send without the requested format, then it just read as if the user location is is my server location.
That seems very strange and non-standard. Whatever service you’re proxying to should handle the X-Forwarded-For
header.
You can use the {remote_host}
placeholder to get the client’s IP address. This might not always be correct though, because this will only give you the address of the next immediate client – if you’re running your Caddy site behind another proxy, then you’ll be seeing the IP of that proxy. The X-Forwarded-For
solves this by it being an appended list at each proxy hop (as long as the proxy is well behaved and does so).
It’s still unclear what the request body you’re dealing with looks like. If it’s HTML, I’d say that it would be very difficult to deal with.
Currently, Caddy doesn’t support any way to rewrite request bodies, but it would be possible with a plugin.
The request body is just text/plain.
About X-Forwarded-For
, How do I read from this instead?
And place it in query params, it is the alternative of HTTP body
You can use a rewrite
to append the query to the URL. Something like:
rewrite @proxiedRequests {path}?client_ip={remote_host}&{query}
You didn’t fill out the thread template so I can’t help much more than that without seeing what your Caddyfile looks like.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.