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.
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.
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.
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
Log on to the Alibaba Cloud CDN console.
In the left-side navigation pane, click Domain Names.
On the Domain Names page, find the domain name that you want to manage and click Manage in the Actions column.
In the left-side navigation tree of the domain name, click Origin Fetch.
In the Default Origin Host section, click Modify.
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.
NoteIf 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.
NoteMake 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.
Click OK.
Sample configurations
Example 1: The address of the origin server is a domain name.
Domain Name | Description |
Accelerated domain name:
Address of the origin server:
| By default, the feature is disabled. You can enable the default origin host feature. Description of domain types:
|
Example 2: The address of the origin server is an IP address.
Domain Name | Description |
Accelerated domain name:
Address of the origin server:
| By default, the feature is disabled. You can enable the default origin host feature. Description of domain types:
|
Example 3: The address of the origin server is an OSS domain name.
Domain Name | Description |
Accelerated domain name:
Address of the origin server:
| 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:
|