HTTP Headers
You can configure the Forwarded
, X-Forwarded-*
and X-Real-IP
headers of outbound requests with these options:
- Set headers:
forwarded.set_outbound.forwarded
: sets theForwarded
header per RFC 7239 specifications, using the parametersfor
,by
,host
, andproto
forwarded.set_outbound.x-forwarded
: setsX-Forwarded-For
header to chain of IP addresses from the original client to the last proxy serverforwarded.set_outbound.x-real-ip
: sets theX-Real-IP
header to the original client IP address
- Preserve headers of the inbound request (use only if you trust the request source):
forwarded.preserve_inbound.forwarded
: preserves the inboundForwarded
headerforwarded.preserve_inbound.x-forwarded
: preserves the inboundX-Forwarded-For
headerforwarded.preserve_inbound.x-real-ip
: preserves the inboundX-Real-IP
header
caution
Only preserve inbound headers if you trust the source of the inbound request to avoid spoofed headers.
Here's an example configuration:
- Environment variables
- HCL
- JSON
- TOML
- YAML
GATE_HEADERS_FORWARDED_SET_OUTBOUND_FORWARDED=true
GATE_HEADERS_FORWARDED_SET_OUTBOUND_X_FORWARDED=true
GATE_HEADERS_FORWARDED_SET_OUTBOUND_X_REAL_IP=true
GATE_HEADERS_FORWARDED_PRESERVE_INBOUND_FORWARDED=true
GATE_HEADERS_FORWARDED_PRESERVE_INBOUND_X_FORWARDED=true
GATE_HEADERS_FORWARDED_PRESERVE_INBOUND_X_REAL_IP=true
gate = {
headers = {
forwarded = {
set_outbound = {
forwarded = true
x-forwarded = true
x-real-ip = true
}
preserve_inbound = {
forwarded = true
x-forwarded = true
x-real-ip = true
}
}
}
}
{
"gate": {
"headers": {
"forwarded": {
"set_outbound": {
"forwarded": true,
"x-forwarded": true,
"x-real-ip": true
},
"preserve_inbound": {
"forwarded": true,
"x-forwarded": true,
"x-real-ip": true
}
}
}
}
}
[gate.headers]
forwarded.set_outbound.forwarded = true
forwarded.set_outbound.x-forwarded = true
forwarded.set_outbound.x-real-ip = true
forwarded.preserve_inbound.forwarded = true
forwarded.preserve_inbound.x-forwarded = true
forwarded.preserve_inbound.x-real-ip = true
gate:
headers:
forwarded:
set_outbound:
forwarded: true
x-forwarded: true
x-real-ip: true
preserve_inbound:
forwarded: true
x-forwarded: true
x-real-ip: true
To debug issues with the configuration of HTTP headers, use log level trace
.
Disable Via
headers
By default, Gate adds a Via
header to all response.
You can disable this behaviour with the following option:
- Environment variables
- HCL
- JSON
- TOML
- YAML
GATE_HEADERS_VIA_DISABLED=true
gate = {
headers = {
via = {
disabled = true
}
}
// ...
}
{
"gate": {
"headers": {
"via": {
"disabled": true
}
}
// ...
[gate.headers]
via.disabled = true
gate:
headers:
via:
disabled: true