How to capture client IP address #3305
-
The documentation show code that is setting the client_addr from the request.headers x-forwarded-for value. But request.headers does not have a x-forwarded-for set for me. Is there ANY other way to capture the client's IP address? I do see it being logged in the journalctl so I know that PostgREST is capturing it...
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
PostgREST only shows the client's IP it in the logs, as you have mentioned. In order for you to handle the IP, your reverse proxy needs to explicitly set the For instance, if you use Nginx as a reverse proxy, you can follow the example in the docs and add the header inside the location /api/ {
default_type application/json;
proxy_hide_header Content-Location;
add_header Content-Location /api/$upstream_http_content_location;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_pass http://postgrest/;
# setting the header:
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
} Only then you can access the IP by selecting that header in SQL: select current_setting('request.headers', true)::json->>'x-forwarded-for'; |
Beta Was this translation helpful? Give feedback.
PostgREST only shows the client's IP it in the logs, as you have mentioned. In order for you to handle the IP, your reverse proxy needs to explicitly set the
x-forwarded-for
header.For instance, if you use Nginx as a reverse proxy, you can follow the example in the docs and add the header inside the
location
:Only …