-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Description
Issue Details
caddy version
v2.10.2 h1:g/gTYjGMD0dec+UgMw8SnfmJ3I9+M2TdvoRL/Ovu6U8=
my Caddyfile contains below settings:
(uat_proxy) {
@match_routes {
path_regexp ^/(([_a-z0-9A-Z]{1,2}.(txt|html))|f|axfa|xxas|hype)($|/)
}
header {
>via "Caddy" "MyProxy"
}
reverse_proxy @match_routes {args[1]} {
header_up Host "{args[0]}"
header_up X-Real-IP {http.request.remote.host}
header_up X-SCHEME {http.request.scheme}
header_up -Strict-Transport-Security;
}
abort
}
https://uat.caddy.test.com {
route {
import uat_proxy caddy-proxy.test.com https://upstream.test.com
}
import log_file uat.caddy.test.com
import acme_all
}
The upstream server upstream.test.com is nginx and it's logging $http_x_real_ip as x_real_ip.
But in the nginx log, the x_real_ip doesn't always have value for the same request from same client:
{ "protocol": "http", "server_name": "caddy-proxy.test.com", "clientip": "113.100.11.42", "time_local": "21/Nov/2025:17:37:18 +0800", "time_msec": 1763717838.617, "status": 200, "request_o": "GET /f/abcd HTTP/1.1", "request_wo_args": "/f/abcd", "body_sent": 54288, "referrer": "", "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36", "x_forwarded_for": "113.100.11.42, 52.13.118.114", "x_real_ip": "", "request_time": 1.348, "upstream_addr": "127.0.0.1:8086", "upstream_status": "200", "upstream_response_time": "1.347" }
{ "protocol": "http", "server_name": "caddy-proxy.test.com", "clientip": "113.100.11.42", "time_local": "21/Nov/2025:17:37:35 +0800", "time_msec": 1763717855.498, "status": 200, "request_o": "GET /f/abcd HTTP/1.1", "request_wo_args": "/f/abcd", "body_sent": 54286, "referrer": "", "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36", "x_forwarded_for": "113.100.11.42, 52.13.118.114", "x_real_ip": "113.100.11.42", "request_time": 0.627, "upstream_addr": "127.0.0.1:8086", "upstream_status": "200", "upstream_response_time": "0.626" }
Assistance Disclosure
No response
If AI was used, describe the extent to which it was used.
No response