Skip to content

help request: How to Set X-Forwarded-Host and X-Forwarded-Port in APISIX When Using a Second Proxy? #12721

@deekshith-hadil

Description

@deekshith-hadil

Description

I have a scenario where APISIX acts as the primary proxy for most users. However, in certain cases, some users access our services via a second proxy, which then forwards the request to APISIX. The architecture is illustrated below:

flowchart LR
    subgraph User Side
        User1["User"]
        User2["User (via 2nd Proxy)"]
    end

    subgraph Front Proxy
        FrontProxy["Proxy #2"]
    end

    subgraph APISIX Layer
        APISIX["APISIX (Proxy)"]
    end

    subgraph Backend
        HTTPPod["HTTP Pod"]
    end

    User1 -- HTTP Request --> APISIX
    User2 -- HTTP Request --> FrontProxy
    FrontProxy -- Forwards Request --> APISIX
    APISIX -- Proxies Request --> HTTPPod
Loading

Problem:
When a request comes via Proxy #2, I want APISIX to identify and set the X-Forwarded-Host and X-Forwarded-Port headers to the values from Proxy #2, rather than its own (APISIX pod) host and port.

I understand that a custom plugin could potentially achieve this, but so far, APISIX does not override X-Forwarded-Host and X-Forwarded-Port as expected—it continues to set them to APISIX's own host and port.

What I've Tried

  • proxy-rewrite plugin
  • serverless-pre-function plugin
  • serverless-post-function plugin

I've followed the discussions and suggestions in the threads below, but none of these solutions have worked for me:


Questions:

  • Is there a recommended way to have APISIX set or override X-Forwarded-Host and X-Forwarded-Port when requests are forwarded by another proxy?
  • Is this currently supported by APISIX, or is it a known limitation?
  • Are there any workarounds or plugins I might have missed?

Any guidance or suggestions would be greatly appreciated!

Environment

  • APISIX version (run apisix version): 3.14.1
  • Operating system (run uname -a): ubuntu
  • OpenResty / Nginx version (run openresty -V or nginx -V): NA
  • etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info): NA
  • APISIX Dashboard version, if relevant: NA
  • Plugin runner version, for issues related to plugin runners: NA
  • LuaRocks version, for installation issues (run luarocks --version): NA
  • Kubernetes environment: Server Version- v1.33.1+k3s1

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionlabel for questions asked by users

    Type

    No type

    Projects

    Status

    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions