Skip to content

Commit e464aca

Browse files
committed
feat: [#272] Explicitly set X-Forwarded-For header in Caddy reverse proxy
Add explicit header_up X-Forwarded-For configuration to Caddyfile.tera instead of relying on Caddy's default behavior. Rationale: - While Caddy sets X-Forwarded-For by default, we explicitly configure it to guard against future changes in Caddy's default behavior - This header is critical for the tracker's on_reverse_proxy mode to correctly identify client IPs for peer tracking in BitTorrent swarms - Explicit configuration makes the intent clear and self-documenting The X-Forwarded-For header is required by the tracker when running behind a reverse proxy to record the correct peer IP addresses.
1 parent 8b6e361 commit e464aca

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

templates/caddy/Caddyfile.tera

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
#
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).
6+
#
7+
# Header Forwarding:
8+
# 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.
613

714
# Global options
815
{
@@ -18,27 +25,38 @@
1825

1926
# Tracker REST API
2027
{{ tracker_api.domain }} {
21-
reverse_proxy tracker:{{ tracker_api.port }}
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+
}
2232
}
2333
{%- endif %}
2434
{%- for http_tracker in http_trackers %}
2535

2636
# HTTP Tracker {{ loop.index }}
2737
{{ http_tracker.domain }} {
28-
reverse_proxy tracker:{{ http_tracker.port }}
38+
reverse_proxy tracker:{{ http_tracker.port }} {
39+
# Explicitly forward client IP - critical for peer tracking accuracy
40+
# The tracker uses this to record the correct peer IP in the swarm
41+
header_up X-Forwarded-For {remote_host}
42+
}
2943
}
3044
{%- endfor %}
3145
{%- if health_check_api %}
3246

3347
# Health Check API
3448
{{ health_check_api.domain }} {
35-
reverse_proxy tracker:{{ health_check_api.port }}
49+
reverse_proxy tracker:{{ health_check_api.port }} {
50+
header_up X-Forwarded-For {remote_host}
51+
}
3652
}
3753
{%- endif %}
3854
{%- if grafana %}
3955

4056
# Grafana UI with WebSocket support
4157
{{ grafana.domain }} {
42-
reverse_proxy grafana:3000
58+
reverse_proxy grafana:3000 {
59+
header_up X-Forwarded-For {remote_host}
60+
}
4361
}
4462
{%- endif %}

0 commit comments

Comments
 (0)