Configure default origin host

Updated at:

By default, the Host header in origin requests sent by CDN is the accelerated domain name. This feature allows you to customize the value of the Host header for these requests.

About default origin hosts

If you serve different static resources from multiple accelerated domain names, a common approach is to set up a separate origin server for each domain.

However, maintaining multiple servers is inefficient, especially for accelerated domain names with low origin traffic. You can solve this problem by using virtual hosting.

Virtual hosting

Virtual hosting allows a single web server to host multiple websites. The server distinguishes and isolates websites by using different domain names or hostnames. When a user requests a specific domain name or hostname, the server routes the request to the matching virtual site and returns the corresponding content.

Nginx implementation

Nginx uses server blocks to configure multiple virtual sites. The following example shows a basic configuration:

server {
    listen      80;
    server_name example.org www.example.org;
    ...
}

server {
    listen      80;
    server_name example.net www.example.net;
    ...
}

server {
    listen      80;
    server_name example.com www.example.com;
    ...
}

This configuration defines three virtual sites: example.org, example.net, and example.com. Nginx matches the Host header with the server_name to select the correct virtual site. If no match is found, Nginx serves content from the default virtual site. If a default site is not explicitly configured, the first server block becomes the default.

Default origin host

When you access a URL, if the Host header is not specified, the Host header of the request defaults to the host and port of the URL. CDN overrides this default by setting the Host header to the accelerated domain name. You can customize this default value based on the virtual hosting configuration of your origin server.

The origin server must be configured to use the Host header to route requests to different virtual sites. Otherwise, this feature will not function correctly.

Important

When your origin server uses the HTTPS protocol, in addition to configuring the default origin host, you typically also need to configure Default Origin SNI. If the origin host and origin SNI are configured inconsistently (for example, HOST is set to the origin domain name while SNI is set to the accelerated domain name), SSL handshake failures or origin server errors may occur. We recommend setting both the origin host and origin SNI to the same domain name (typically the origin domain name or the accelerated domain name, which must match the origin server certificate and virtual host configuration). On the Origin Fetch page of the console, Origin Host and Default Origin SNI are two separate configuration items. You must click Modify for each item separately to configure it.

Procedure

  1. Log on to CDN console.

  2. In the left-side navigation pane, choose Domain Names.

  3. In the domain name list, select the target domain name.

  4. Click the Origin Fetch tab.

  5. In the Origin Host section, click Modify.

  6. Turn on the Origin Host switch and select a Domain Type.

Domain Type

Description

CDN Domain

Sets the origin host to the accelerated domain name.

Origin Domain

Sets the origin host to the origin server domain name. If the origin server is specified by an IP address, this option is dimmed and unavailable. If the origin server is an OSS domain, the feature is automatically enabled and the Origin Host is set to Origin Domain.

Custom Domain

Sets the origin host to a custom domain that you specify. Make sure that the custom domain name is bound to your origin server. Otherwise, origin requests fail. Use this option if your origin server is bound to multiple domain names and you need to fetch resources from a specific one.

Important

When your origin server uses the HTTPS protocol, you must also configure Default Origin SNI on the same Origin Fetch page. We recommend setting Origin Host and Default Origin SNI to the same domain name (typically the origin domain name) to avoid SSL handshake failures or origin server rejections. For example, if Origin Host is set to the origin domain name but Default Origin SNI is set to the accelerated domain name, the origin server's certificate verification may fail. In the console, Origin Host and Default Origin SNI are two separate configuration items on the same Origin Fetch page, and each is configured by using its own Modify button.

  1. Click OK.

Configuration examples

Example 1: The origin server is specified by a domain name

By default, this feature is disabled. You can enable it manually.

Configuration:

  • Accelerated domain name: image.example.com

  • Origin server address: source.example.com

Each Domain Type has the following behavior:

  • CDN Domain: When CDN performs a origin request, it retrieves resources from the virtual site image.example.com on the origin server source.example.com.

  • Origin Domain: When CDN performs a origin request, it retrieves resources from source.example.com.

  • Custom Domain: The origin host is the custom domain name that you entered.

Example 2: The origin server is specified by an IP address

By default, this feature is disabled. You can enable it manually.

Configuration:

  • Accelerated domain name: example.com

  • Origin server address: 10.10.10.10

Each Domain Type has the following behavior:

  • CDN Domain: When CDN performs a origin request, it retrieves resources from the virtual site for example.com on the host 10.10.10.10.

  • Origin Domain: When the origin server is specified by an IP address, this option is dimmed and cannot be selected.

  • Custom Domain: When CDN performs a origin request, it retrieves resources from the virtual site of the custom domain on the 10.10.10.10 host.

Example 3: The origin server is an OSS domain

Configuration:

  • Accelerated domain name: example.com

  • Origin server address: example.oss-cn-hangzhou.aliyuncs.com

When the origin server is an OSS domain, CDN automatically enables the feature and sets the Origin Host to Origin Domain. Each Domain Type has the following behavior:

  • CDN Domain: When CDN performs a origin request, it retrieves resources from the example.com site on the example.oss-cn-hangzhou.aliyuncs.com OSS domain.

  • Origin Domain: When CDN performs a origin request, it retrieves resources from the OSS domain example.oss-cn-hangzhou.aliyuncs.com.

  • Custom Domain: When CDN performs a origin request, it retrieves resources from the virtual site for the custom domain on your example.oss-cn-hangzhou.aliyuncs.com site.

FAQ