How to configure VMware NSX Native Load Balancer to rewrite HTTP Host and URI path
search cancel

How to configure VMware NSX Native Load Balancer to rewrite HTTP Host and URI path

book

Article ID: 435690

calendar_today

Updated On:

Products

VMware NSX

Issue/Introduction

When attempting to route traffic through an VMware NSX Native Load Balancer (LB) to a backend server that expects a different endpoint than the client-requested URL, users may experience the following:

  • HTTP 504 Gateway Timeout errors.
  • Requests reaching the backend server with incorrect Host headers or URI paths, causing application-level rejection.
  • Traffic failing to reach the intended server pool because the load balancer is not translating the request to the backend's required format.

Environment

VMware NSX

Cause

Modern backend services (such as those hosted on Kubernetes or specific application frameworks) often require a specific Host header and URI path to properly route requests. If the client sends a request to a legacy or different URL, the NSX Load Balancer must be configured to perform a double rewrite (Host and Path) before forwarding the request to the server pool.

Resolution

To resolve this, configure Request Rewrite Phase rules on the Layer 7 Virtual Server to modify the incoming request headers and URI before the request is forwarded to the backend pool.

Below are typical examples of URI and header rewrites and redirects which can be used to accomplish the traffic redirection, some or all of these may or additional rules may be required, based on the requirements of the backend pool.

  • Request Rewrite Phase rule details
    • Rule 1:

Match Conditions:
Condition: HTTP Request URI
Match: Equals
URI: </incoming/original/path/>
Case Sensitive: Off
Negate: Off

Match Strategy: ALL

Actions:
Action: HTTP Request URI Rewrite
URI: </new/backend/path/>

  • Request Forwarding rules details:
    • Rule 1:

Condition: HTTP Request Header
Header Name: <Incoming Header Name>
Match Type: Equals
Header Value: <Incoming Header Name Value>
Case Sensitive: Off
Negate: Off

Match Strategy: ALL

Actions
Action: Select Pool
Select Pool: <Pool to send traffic to that matches the header>

    • Rule 2:

Condition: HTTP Request Header
Header Name: <Incoming Header Name>
Match Type: Equals
Header Value: <Incoming Header Name Value>
Case Sensitive: Off
Negate: Off

Match Strategy: ALL

Actions
Action: Select Pool
Select Pool: <Pool to send traffic to that matches the header>

    • Rule 3:

Match Condition
Condition: HTTP Request Header
Header Name: Host
Match Type: Equals
Header Value: <Original host header value>
Case Sensitive: Off
Negate: Off

Match Strategy: ALL

Action: HTTP Request Header Rewrite
Header Name: Host
Header Value: <New host header value>

To verify the rules are working, enable Access Logging on the Virtual Server and check the Active Edge's log: /var/log/lb/<LB-ID>/<virtual server id>/logs/

Additional Information

Further details on configuring a Native Load Balancer rules can be found in section 7 here NSX-T LB 301 ToI / NSX-T LB Encyclopedia