All Products
Search
Document Center

Alibaba Cloud Service Mesh:Enable gzip compression for an ASM ingress gateway

Last Updated:Mar 11, 2026

HTTP responses from backend services often contain compressible text content such as HTML, JSON, and CSS. Without compression, the ingress gateway forwards these responses at full size, which increases bandwidth costs and slows client load times. Gzip compression on the ASM ingress gateway compresses eligible responses before they reach the client, reducing response sizes and improving transfer speed.

How it works

When a client sends an HTTP request with the Accept-Encoding: gzip header, the ingress gateway compresses the response body before returning it. The gateway compresses a response only when all of the following conditions are met:

  • The request includes Accept-Encoding: gzip (or *).

  • The response Content-Type matches one of the types specified in compression.content_type.

  • The response is not already compressed (no existing Content-Encoding header).

If remove_accept_encoding_header is set to true, the gateway strips the Accept-Encoding header before forwarding the request upstream. This prevents the upstream service from compressing the response on its own, keeping the gateway as the single point of compression.

Prerequisites

  • A cluster is added to the ASM instance. See Add a cluster to an ASM instance.

  • An ingress gateway is deployed. See Create an ingress gateway.

  • A sample application is deployed in the Container Service for Kubernetes (ACK) cluster, with a virtual service and Istio gateway routing traffic through the ASM ingress gateway. If you do not have an existing application, see Set up a sample application.

  • An Internet Content Provider (ICP) filing is obtained for a domain name if you want to use one.

Configure gzip compression

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

  2. On the Mesh Management page, find the target ASM instance. Click the instance name or click Manage in the Actions column.

  3. In the left-side navigation pane, choose ASM Gateways > Ingress Gateway.

  4. On the Ingress Gateway page, find the target ingress gateway and click YAML.

  5. In the Edit dialog box, add the following compression block to the YAML and click OK.

       compression:
         content_type:
           - text/html
         enabled: true
         gzip:
           memory_level: 9
         remove_accept_encoding_header: true

Configuration reference

The table below describes the compression fields. For all ingress gateway fields, see Create and manage an ingress gateway by using the Kubernetes API.

FieldDescription
compression.enabledSpecifies whether to enable data compression for the ingress gateway service.
compression.content_typeThe Content-Type values eligible for compression. Only responses with a matching Content-Type header are compressed.
compression.gzip.memory_levelThe amount of internal memory used for compression. Higher values use more memory but can produce better compression.
compression.remove_accept_encoding_headerWhether to strip the Accept-Encoding header before forwarding requests to the upstream service. Set to true to prevent the upstream from double-compressing responses.
Note: Specify multiple content types to compress a wider range of responses. Common types include text/html, application/json, application/javascript, text/css, text/plain, and application/xml.

Verify compression

After you configure compression, confirm that the ingress gateway returns gzip-compressed responses.

  1. Get the external IP address of the ingress gateway.

    1. Log on to the ACK console. In the left-side navigation pane, click Clusters.

    2. On the Clusters page, click the cluster name. In the left-side navigation pane, choose Network > Services.

    3. On the Services page, select istio-system from the Namespace drop-down list. Find istio_ingressgateway and note the IP address for port 80 in the External IP column.

  2. Send a request with the Accept-Encoding: gzip header and check the response headers. Replace <ingress-gateway-ip> with the external IP address from step 1.

       curl -s -o /dev/null -D - -H "Accept-Encoding: gzip" http://<ingress-gateway-ip>/
  3. Check the output. If the response includes content-encoding: gzip, compression is working.

       HTTP/1.1 200 OK
       content-encoding: gzip
       content-type: text/html
       ...

    If the content-encoding header is absent, verify the following:

    • The request includes the Accept-Encoding: gzip header.

    • The response Content-Type matches a type listed in compression.content_type.

    • compression.enabled is set to true.

    • The response is not already compressed by the upstream service. If remove_accept_encoding_header is false, the upstream may have applied its own compression, and the gateway skips re-compression.

    Alternatively, open Chrome DevTools (More tools > Developer tools), navigate to the ingress gateway IP address, and look for content-encoding: gzip in the Response Headers section of the Network tab.

Set up a sample application (optional)

If you do not have an existing application behind the ingress gateway, deploy a sample NGINX application with the required Istio gateway and virtual service.

Step 1: Deploy the NGINX application

Create a file named nginx.yaml with the following content and apply it to the ACK cluster.

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: nginx-deployment
spec:
  selector:
    matchLabels:
      app: nginx
  replicas: 1
  template:
    metadata:
      labels:
        app: nginx
        sidecarset-injected: "true"
    spec:
      containers:
      - name: nginx
        image: nginx:1.14.2
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: nginx
spec:
  ports:
    - name: http
      port: 80
      protocol: TCP
      targetPort: 80
  selector:
    app: nginx
  type: ClusterIP
kubectl apply -f nginx.yaml

Step 2: Create the Istio gateway and virtual service

  1. In the ASM console, navigate to the details page of your ASM instance.

  2. In the left-side navigation pane, choose ASM Gateways > Gateway. Click Create from YAML.

  3. Select a namespace, paste the following YAML, and click Create.

       apiVersion: networking.istio.io/v1beta1
       kind: Gateway
       metadata:
         name: nginx-gateway
         namespace: default
       spec:
         selector:
           istio: ingressgateway
         servers:
           - hosts:
               - '*'
             port:
               name: http
               number: 80
               protocol: HTTP
  4. In the left-side navigation pane, choose Traffic Management Center > VirtualService. Click Create from YAML.

  5. Select a namespace, paste the following YAML, and click Create.

       apiVersion: networking.istio.io/v1beta1
       kind: VirtualService
       metadata:
         name: nginx
         namespace: default
       spec:
         gateways:
           - nginx-gateway
         hosts:
           - '*'
         http:
           - match:
               - uri:
                   exact: /
             route:
               - destination:
                   host: nginx
                   port:
                     number: 80

After the gateway and virtual service are created, return to Configure gzip compression to enable compression on the ingress gateway.

What's next