Skip to content

Commit 28336e0

Browse files
committed
refactor: [#272] Set X-Forwarded-For header only for HTTP trackers
The X-Forwarded-For header is critical only for HTTP trackers where the tracker needs the real client IP to record correct peer addresses in the swarm. Other services (API, health check, Grafana) don't require explicit header configuration as Caddy's default forwarding is sufficient. This change: - Keeps explicit header_up X-Forwarded-For {remote_host} for HTTP trackers - Removes explicit header for API, health check, and Grafana endpoints - Updates header comment to clarify it's for HTTP trackers specifically
1 parent e464aca commit 28336e0

1 file changed

Lines changed: 8 additions & 15 deletions

File tree

templates/caddy/Caddyfile.tera

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
# This template generates a Caddyfile based on which services have TLS configured.
55
# Services without TLS configuration will not have entries here (they remain HTTP-only).
66
#
7-
# Header Forwarding:
7+
# Header Forwarding for HTTP Trackers:
88
# Caddy sets X-Forwarded-For, X-Forwarded-Proto, and X-Forwarded-Host by default.
9-
# We explicitly set X-Forwarded-For to ensure this behavior is maintained even if
10-
# Caddy's defaults change in future versions. The tracker requires X-Forwarded-For
11-
# when running behind a reverse proxy (on_reverse_proxy: true) to correctly identify
12-
# the original client IP address for peer tracking.
9+
# We explicitly set X-Forwarded-For for HTTP trackers to ensure this behavior is
10+
# maintained even if Caddy's defaults change in future versions. The tracker requires
11+
# X-Forwarded-For when running behind a reverse proxy (on_reverse_proxy: true) to
12+
# correctly identify the original client IP address for peer tracking.
1313

1414
# Global options
1515
{
@@ -25,10 +25,7 @@
2525

2626
# Tracker REST API
2727
{{ tracker_api.domain }} {
28-
reverse_proxy tracker:{{ tracker_api.port }} {
29-
# Explicitly forward client IP - required for tracker's on_reverse_proxy mode
30-
header_up X-Forwarded-For {remote_host}
31-
}
28+
reverse_proxy tracker:{{ tracker_api.port }}
3229
}
3330
{%- endif %}
3431
{%- for http_tracker in http_trackers %}
@@ -46,17 +43,13 @@
4643

4744
# Health Check API
4845
{{ health_check_api.domain }} {
49-
reverse_proxy tracker:{{ health_check_api.port }} {
50-
header_up X-Forwarded-For {remote_host}
51-
}
46+
reverse_proxy tracker:{{ health_check_api.port }}
5247
}
5348
{%- endif %}
5449
{%- if grafana %}
5550

5651
# Grafana UI with WebSocket support
5752
{{ grafana.domain }} {
58-
reverse_proxy grafana:3000 {
59-
header_up X-Forwarded-For {remote_host}
60-
}
53+
reverse_proxy grafana:3000
6154
}
6255
{%- endif %}

0 commit comments

Comments
 (0)