All Products
Search
Document Center

CDN:Configure the default origin host

Last Updated:Nov 09, 2023

By default, the value of the HOST header in a back-to-origin request is the accelerated domain name. You can also specify a custom value for the HOST header.

Background information

If you have multiple accelerated domain names, each of which is used to accelerate different static resources. A common practice is to deploy multiple origin servers. This way, requests that are destined for different accelerated domain names can be redirected to different origin servers.

image

If you have a large number of accelerated domain names and a small amount of origin traffic, deploying multiple origin servers may result in a waste of resources. In this case, you can use virtual hosting.

Virtual hosting

Virtual hosting allows you to host multiple websites on a single web server. A server distinguishes and isolates different websites by domain name or hostname. When a user accesses a specific domain name or hostname, the server directs the request to the corresponding virtual site based on the domain name or hostname in the request to retrieve the required content. The following figure shows how virtual hosting works.

image

NGINX-related implementations

NGINX allows you to configure multiple virtual sites by using server blocks. The following sample code provides an example on how to configure multiple virtual sites:

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;
    ...
}

A project is configured with three virtual sites, which are example.org, example.net and example.com. NGINX determines the destination virtual site based on the value of the HOST header in the HTTP request. If no virtual site is matched, NGINX uses the default virtual site. If no default virtual site is configured, the virtual site that is specified by the first server block is used as the default virtual site.

Default origin host

If you access a URL without specifying the HOST header, the value of the HOST header is the host and the port in the URL. However, Alibaba Cloud CDN uses the accelerated domain name as the value of the HOST header by default. You can specify a default value for the HOST header for virtual sites in your origin server.

Important

Your origin server must support matching different virtual sites based on the value of the HOST header. Otherwise, the feature does not work as expected.

Procedure

  1. Log on to the Alibaba Cloud CDN console.

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

  3. On the Domain Names page, find the domain name that you want to manage and click Manage in the Actions column.

    Domain Names
  4. In the left-side navigation pane of the domain name, click Back-to-origin.

  5. In the Default Origin Host section, click Modify.

  6. Turn on Origin Host and configure the Domain Type parameter.

    回源配置

    Parameter

    Description

    CDN Domain

    The domain name that users visit is used as the origin host.

    Origin Domain

    The domain name of the origin server is used as the origin host.

    Note
    • If you set the type of the origin server to IP when you add an origin server, Origin Domain is dimmed.

    • If you set the type of the origin server to OSS Domain when you add an origin server, Origin Host is turned on and the Domain Type parameter is set to Origin Domain.

    Custom Domain

    The domain name that you specify is used as the origin host.

    Note
    • Make sure that the custom domain name is associated with the origin server. Otherwise, origin fetch fails.

    • Your origin server is associated with multiple domain names, and you specify a domain name to which requests are redirected.

  7. Click OK.

Sample configuration

Example 1: The address of the origin server is a domain name.

Domain Name

Description

Accelerated domain name:

image.example.com

Address of the origin server:

source.example.com

By default, the feature is disabled. You can enable the default origin host feature.

Description of domain types:

  • CDN Domain: Alibaba Cloud CDN redirects back-to-origin requests to the virtual site image.example.com that is hosted on the origin server source.example.com.

  • Origin Domain: Alibaba Cloud CDN redirects back-to-origin requests to the origin server source.example.com.

  • Custom Domain: Alibaba Cloud CDN redirects back-to-origin requests to the specified custom domain name.

Example 2: The address of the origin server is an IP address.

Domain Name

Description

Accelerated domain name:

example.com

Address of the origin server:

10.10.10.10

By default, the feature is disabled. You can enable the default origin host feature.

Description of domain types:

  • CDN Domain: Alibaba Cloud CDN redirects back-to-origin requests to the virtual site example.com that is hosted on the origin server 10.10.10.10.

  • Origin Domain: If you set the type of the origin server to IP when you add an origin server, Origin Domain is dimmed.

  • Custom Domain: Alibaba Cloud CDN redirects back-to-origin requests to the virtual site that uses a custom domain name and that is hosted on 10.10.10.10.

Example 3: The address of the origin server is an OSS domain name.

Domain Name

Description

Accelerated domain name:

example.com

Address of the origin server:

example.oss-cn-hangzhou.aliyuncs.com

If the address of the origin server is an OSS domain name, Alibaba Cloud CDN automatically enables the origin host feature and sets the Domain Type parameter to Origin Domain.

Description of domain types:

  • CDN Domain: Alibaba Cloud CDN redirects back-to-origin requests to example.com on the origin server example.oss-cn-hangzhou.aliyuncs.com.

  • Origin Domain: Alibaba Cloud CDN redirects back-to-origin requests to the origin server example.oss-cn-hangzhou.aliyuncs.com.

  • Custom Domain: Alibaba Cloud CDN redirects back-to-origin requests to the virtual site that uses a custom domain name and that is hosted on example.oss-cn-hangzhou.aliyuncs.com.