All Products
Search
Document Center

Microservices Engine:Serve static website content through an MSE cloud-native gateway and OSS

Last Updated:Mar 11, 2026

In a frontend-backend separation architecture, static assets (HTML, CSS, JavaScript) live in object storage while backend services run independently. When your application already uses a Microservices Engine (MSE) cloud-native gateway to route API traffic, you can add Object Storage Service (OSS) as a backend service on the same gateway. This gives you a single entry point for both static content and backend APIs, with gateway-level URL rewriting, header manipulation, and routing policies applied to all traffic.

This tutorial walks through storing static files in an OSS bucket and configuring an MSE cloud-native gateway to serve them. After you finish, the gateway routes requests such as example.com/index.html to files in OSS and requests such as example.com/app to backend services.

When to use this approach

Use an MSE cloud-native gateway to serve static content from OSS when:

  • Your application already uses an MSE cloud-native gateway for backend API routing, and you want a single entry point for both static assets and APIs.

  • You need URL rewriting, header manipulation, or other gateway-level policies for static content.

For a standalone static website without backend services, OSS static website hosting is a simpler alternative.

How it works

The following diagram shows the request flow:

Client request
     |
     v
MSE cloud-native gateway
     |
     |-- /index.html, /style.css, ...  -->  OSS bucket (static files)
     |
     +-- /app, /api/...               -->  Backend services

The gateway matches each incoming request against its route rules. Static file requests go to the OSS bucket's internal endpoint, with the host header rewritten so that OSS resolves the correct bucket. The content-disposition response header is removed so that browsers render files inline instead of downloading them.

Prerequisites

Before you begin, make sure that you have:

Step 1: Create an OSS bucket and upload a static page

Create a public-read OSS bucket and upload a sample HTML page.

  1. Log on to the OSS console.

  2. In the left-side navigation pane, click Buckets, and then click Create Bucket.

  3. In the Create Bucket panel, configure the following parameters and keep the defaults for all others. Then click OK.

    A public-read ACL allows anyone to read objects in this bucket. For production workloads, evaluate whether a more restrictive ACL with signed URLs is appropriate for your security requirements.
    ParameterValue
    Bucket NameEnter a bucket name. This tutorial uses static-demo-0.
    Storage ClassSelect Standard.
    ACLClick Public Read. When the Are you sure you want to select Public Read? confirmation appears, click Continue.
  4. On the Buckets page, click the name of the bucket you created. In the Objects pane, click Upload Object.

  5. Set Object ACL to Inherited from Bucket and upload the following index.html file:

       <html>
          <head>
              <title>Hello OSS!</title>
              <meta charset="utf-8">
          </head>
          <body>
              <p>Configure static website hosting for Alibaba Cloud OSS.</p>
              <p>This is the index page.</p>
          </body>
       </html>
  6. Click Upload Object. After the upload completes, the file name, size, and storage class appear in the destination directory.

    Upload file

Step 2 (optional): Set a default homepage and a 404 error page

Configure a default homepage so that requests to / return index.html. You can also configure a custom 404 page for unmatched paths.

Set a default homepage

In the OSS console, open your bucket settings and set index.html as the default homepage.

Set homepage

Set a custom 404 page

  1. Upload a 404.html file to the bucket:

       <html>
          <head>
              <title>The page you visited does not exist</title>
              <meta charset="utf-8">
          </head>
          <body>
              <p>The page you visited does not exist.</p>
              <p>You can try to visit the homepage.</p>
          </body>
       </html>
  2. In the bucket's static website hosting settings, set 404.html as the error page.

    Set 404 page

For detailed instructions, see Configure static website hosting.

Step 3: Get the internal endpoint of the OSS bucket

Every OSS bucket has a default domain name. You need the internal endpoint to configure the gateway service in the next step.

In the OSS console, open the bucket's Overview page and find the internal endpoint in the Port section. The endpoint follows the format <bucket-name>.oss-<region>-internal.aliyuncs.com.

Bucket endpoint

For more information, see Access OSS from an ECS instance through an internal endpoint.

Step 4: Add the OSS bucket as a gateway service

The MSE cloud-native gateway treats each OSS bucket as a DNS-discovered service. Register the bucket's internal endpoint as a service on the gateway.

  1. Log on to the MSE console.

  2. In the left-side navigation pane, choose Cloud-native Gateway > Gateways. Click the name of your gateway.

  3. In the left-side navigation pane, click Routes. On the page that appears, click the Services tab.

  4. Click Add Service and configure the following parameters in the Add Service panel. Then click OK.

    ParameterValue
    Service SourceSelect DNS Domain Name.
    Service NameEnter a name for the service. This tutorial uses static.
    Service PortEnter 80.
    Domain NamesEnter the internal endpoint from Step 3, for example, static-demo-0.oss-cn-hangzhou-internal.aliyuncs.com.
    TLS modeSelect Disabled.

Step 5: Create a route and configure policies

Create a route that forwards static file requests to the OSS service, then add a rewrite policy and a header policy.

Create the route

  1. Log on to the MSE console.

  2. In the left-side navigation pane, choose Cloud-native Gateway > Gateways. Click the name of your gateway.

  3. In the left-side navigation pane, click Routes, and then click the Routes tab.

  4. Click Add Route. Set the matching rule to Prefix, the path to /, and the destination service to static. For more information, see Create a route.

Add a rewrite policy

The rewrite policy rewrites the host header so that OSS resolves the correct bucket when the gateway forwards the request.

  1. On the Routes tab, click the name of the route you created. Click the Policies tab.

  2. In the left-side navigation pane of the Policies tab, click Rewrite. Enter the internal endpoint of the OSS bucket (for example, static-demo-0.oss-cn-hangzhou-internal.aliyuncs.com) in the Destination Host field, and click Save. For more information, see Configure a rewrite policy.

Remove the content-disposition response header

By default, OSS sets a content-disposition header that causes browsers to download files instead of rendering them. Remove this header so that static pages display correctly in the browser.

  1. In the left-side navigation pane of the Policies tab, click Edit Header. Add a policy to delete the content-disposition header from OSS responses, and enable the policy. For more information, see Configure a header setting policy.

Verify the result

Test the setup by visiting the following URLs in a browser. Replace example.com with your service domain name.

URLExpected result
example.comReturns index.html (the default homepage configured in Step 2).
example.com/index.htmlReturns index.html directly.
example.com/testReturns 404.html (the custom error page configured in Step 2).

Production considerations

After you verify basic functionality, consider the following before serving production traffic:

  • HTTPS: Configure an SSL certificate on the MSE cloud-native gateway to serve static content over HTTPS.

  • Caching: Add Alibaba Cloud CDN in front of the gateway, or configure cache policies on the gateway, to reduce latency and OSS access costs.

  • Access control: Tighten the bucket ACL and use signed URLs or gateway-level authentication instead of public-read access.