Skip to content

help request: Unable to remove or override X-Forwarded-Host header per-route using any plugin #13753

Description

@mayankmurari

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status
    📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions