Log real client IPs via Fly-Client-IP header #130

Merged
eblume merged 2 commits from fix/real-client-ip-logging into main 2026-02-09 11:02:07 -08:00
4 changed files with 4 additions and 1 deletions

View file

@ -242,7 +242,7 @@ data:
"wrapLogMessage": false
},
"targets": [
{ "datasource": { "type": "loki", "uid": "loki" }, "expr": "{instance=\"flyio-proxy\", job=\"flyio-nginx\"} |= \"docs.eblu.me\"", "refId": "A" }
{ "datasource": { "type": "loki", "uid": "loki" }, "expr": "{instance=\"flyio-proxy\", job=\"flyio-nginx\"} |= \"docs.eblu.me\" | json | line_format \"{{.client_ip}} {{.request_method}} {{.request_uri}} {{.status}} cache={{.upstream_cache_status}} {{.request_time}}s\"", "refId": "A" }
],
"title": "Recent Access Logs",
"type": "logs"

View file

@ -0,0 +1 @@
Log real client IPs in Fly.io proxy access logs using Fly-Client-IP header instead of showing the internal proxy address.

View file

@ -24,6 +24,7 @@ loki.process "nginx" {
// Parse the JSON log line
stage.json {
expressions = {
client_ip = "client_ip",
status = "status",
method = "request_method",
host = "http_host",

View file

@ -13,6 +13,7 @@ http {
'{'
'"time":"$time_iso8601",'
'"remote_addr":"$remote_addr",'
'"client_ip":"$http_fly_client_ip",'
'"request_method":"$request_method",'
'"request_uri":"$request_uri",'
'"status":$status,'