All Products
Search
Document Center

Alibaba Cloud Service Mesh:Rewrite the Host header in a VirtualService

Last Updated:Mar 11, 2026

When a VirtualService routes traffic from one service to another, the destination service may reject the request if the Host or Authority header still contains the original hostname. Service Mesh (ASM) lets the sidecar proxy rewrite these headers to match the destination before forwarding the request, so the destination service accepts it.

How it works

With host rewriting enabled, the request flow works as follows:

  1. The sleep pod sends a request to nginx:8000/headers.

  2. The VirtualService matches the request and applies the rewrite rule, changing the Authority header to httpbin:8000.

  3. The sidecar proxy forwards the request to the HTTPBin service instead of NGINX.

  4. HTTPBin receives the request with the rewritten Host header (httpbin:8000) and returns the headers in its response.

Prerequisites

Before you begin, make sure that you have:

  • Completed the preparations described in Preparations

  • Deployed the HTTPBin, sleep, and NGINX services in the mesh

Create the rewrite rule

  1. Log on to the ASM console. In the left-side navigation pane, choose Service Mesh > Mesh Management.

  2. On the Mesh Management page, click the name of the ASM instance. In the left-side navigation pane, choose Traffic Management Center > VirtualService. On the page that appears, click Create.

  3. On the Mesh Management page, click the name of the target ASM instance.

  4. In the left-side navigation pane, choose Traffic Management Center > VirtualService, then click Create.

  5. On the Create page, configure the parameters as shown in the following screenshot, then click Preview.

    VirtualService creation page

    The following code shows the YAML file for preview:

    apiVersion: networking.istio.io/v1beta1
    kind: VirtualService
    metadata:
      name: nginx
      namespace: default
    spec:
      hosts:
        - nginx.default.svc.cluster.local
      http:
        - rewrite:
            authority: 'httpbin:8000'
          route:
            - destination:
                host: httpbin.default.svc.cluster.local
  6. Confirm that the YAML content is correct, click Submit, then click Create.

Verify the configuration

After you create the VirtualService, confirm that host rewriting takes effect.

  1. Connect to the Container Service for Kubernetes (ACK) cluster with kubectl, then run the following command:

    kubectl exec -it deploy/sleep -- curl nginx:8000/headers
  2. Check the output. If the rewrite rule is working, the Host header shows httpbin:8000 instead of the original NGINX hostname:

    {
      "headers": {
        "Accept": "*/*",
        "Host": "httpbin:8000",
        "User-Agent": "curl/8.1.2"
      }
    }

    This output confirms two things:

    • The request from the sleep pod to nginx:8000/headers was forwarded to the HTTPBin service's /headers endpoint.

    • The Host header was rewritten from the NGINX hostname to httpbin:8000.

See also