Description
I need to remove (or clear) the X-Forwarded-Host header for a specific API route before it reaches the upstream service. Despite trying every available approach, APISIX always sends the original Host header value as X-Forwarded-Host to the upstream.
What I've Tried
1. proxy-rewrite with headers.remove
{
"plugins": {
"proxy-rewrite": {
"headers": {
"remove": ["X-Forwarded-Host"]
}
}
}
}
Result: X-Forwarded-Host still sent to upstream with original value.
2. proxy-rewrite with headers.set (empty string)
{
"plugins": {
"proxy-rewrite": {
"headers": {
"set": {
"X-Forwarded-Host": ""
}
}
}
}
}
Result: X-Forwarded-Host still sent to upstream with original value. Not overridden to empty string.
3. proxy-rewrite with host field
{
"plugins": {
"proxy-rewrite": {
"host": "my-upstream.example.com"
}
}
}
Result: X-Forwarded-Host unchanged.
4. Upstream pass_host: rewrite with upstream_host
{
"upstream": {
"pass_host": "rewrite",
"upstream_host": "my-upstream.example.com",
"nodes": { "my-upstream.example.com:443": 1 },
"scheme": "https"
}
}
Result: X-Forwarded-Host still sent with the APISIX ingress hostname.
5. serverless-pre-function setting ngx.var.var_x_forwarded_host
{
"plugins": {
"serverless-pre-function": {
"phase": "before_proxy",
"functions": [
"return function(conf, ctx) ngx.var.var_x_forwarded_host = '' end"
]
}
}
}
Result: Plugin accepted (no errors), but X-Forwarded-Host still sent with original value.
6. Custom plugin in before_proxy phase
Created a custom Lua plugin that runs in the before_proxy phase and sets ngx.var.var_x_forwarded_host = ''.
Result: Plugin accepted, but X-Forwarded-Host still sent with original value.
Expected Behavior
At least one of the following should work:
proxy-rewrite with headers.remove: ["X-Forwarded-Host"] should prevent the header from being sent upstream
proxy-rewrite with headers.set: { "X-Forwarded-Host": "" } should override the header value
serverless-pre-function with ngx.var.var_x_forwarded_host = '' in before_proxy phase should clear the Nginx variable before proxy_set_header uses it
- A custom plugin in
before_proxy phase should be able to modify var_x_forwarded_host
Actual Behavior
None of the above approaches have any effect on the X-Forwarded-Host header. The upstream always receives X-Forwarded-Host set to the APISIX ingress hostname.
Environment
APISIX Version: 3.17.0
Deployment: Standalone with APISIX Ingress Controller
OS: Linux (K8s pods)
Description
I need to remove (or clear) the
X-Forwarded-Hostheader for a specific API route before it reaches the upstream service. Despite trying every available approach, APISIX always sends the originalHostheader value asX-Forwarded-Hostto the upstream.What I've Tried
1.
proxy-rewritewithheaders.remove{ "plugins": { "proxy-rewrite": { "headers": { "remove": ["X-Forwarded-Host"] } } } }Result:
X-Forwarded-Hoststill sent to upstream with original value.2.
proxy-rewritewithheaders.set(empty string){ "plugins": { "proxy-rewrite": { "headers": { "set": { "X-Forwarded-Host": "" } } } } }Result:
X-Forwarded-Hoststill sent to upstream with original value. Not overridden to empty string.3.
proxy-rewritewithhostfield{ "plugins": { "proxy-rewrite": { "host": "my-upstream.example.com" } } }Result:
X-Forwarded-Hostunchanged.4. Upstream
pass_host: rewritewithupstream_host{ "upstream": { "pass_host": "rewrite", "upstream_host": "my-upstream.example.com", "nodes": { "my-upstream.example.com:443": 1 }, "scheme": "https" } }Result:
X-Forwarded-Hoststill sent with the APISIX ingress hostname.5.
serverless-pre-functionsettingngx.var.var_x_forwarded_host{ "plugins": { "serverless-pre-function": { "phase": "before_proxy", "functions": [ "return function(conf, ctx) ngx.var.var_x_forwarded_host = '' end" ] } } }Result: Plugin accepted (no errors), but
X-Forwarded-Hoststill sent with original value.6. Custom plugin in
before_proxyphaseCreated a custom Lua plugin that runs in the
before_proxyphase and setsngx.var.var_x_forwarded_host = ''.Result: Plugin accepted, but
X-Forwarded-Hoststill sent with original value.Expected Behavior
At least one of the following should work:
proxy-rewritewithheaders.remove: ["X-Forwarded-Host"]should prevent the header from being sent upstreamproxy-rewritewithheaders.set: { "X-Forwarded-Host": "" }should override the header valueserverless-pre-functionwithngx.var.var_x_forwarded_host = ''inbefore_proxyphase should clear the Nginx variable beforeproxy_set_headeruses itbefore_proxyphase should be able to modifyvar_x_forwarded_hostActual Behavior
None of the above approaches have any effect on the
X-Forwarded-Hostheader. The upstream always receivesX-Forwarded-Hostset to the APISIX ingress hostname.Environment
APISIX Version: 3.17.0
Deployment: Standalone with APISIX Ingress Controller
OS: Linux (K8s pods)