Bind the custom domain name to the bucket default domain name

important

This article contains important information that needs your attention. Ignoring this information may affect your business. Please read it carefully.

For security reasons, when you pass the Bucket When the default domain name accesses some files, it may trigger forced download or prohibit download. If you want to preview or download these files in the browser normally, you need to Bucket Bind a custom domain name and access it through the custom domain name OSS File. Binding custom domain names will not affect Bucket The default domain name, you can continue through Bucket Default domain name access OSS File.

Use Scenarios

  • Preview Area : For safety reasons, through OSS Default Bucket When the domain name accesses the file, OSS The download response header will be forced to increase, causing the browser to force the download of files. Accessing a file using a custom domain name will not force the addition of a download response header, so that the file can be previewed in the browser. About using OSS Default for Bucket The domain name accesses the file, and triggers the effective time and effective object of the automatic download. See Appendix: Forced Download Hit x-oss-ec rule

  • Visit. apk Or. ipa file : For safety reasons, through OSS default Bucket Domain Access.apk Or. ipa File, OSS Will return four hundred Error, error code is ApkDownloadForbidden . Use a custom domain name to access. apk Or. ipa The file will not be blocked.

  • Brand image and professionalism : Bind custom domain names, enhance brand image and professionalism, and increase user trust.

  • Prevent domain name from being blocked : Bind a custom domain name to prevent the default domain name from being blocked and ensure normal access to resources.

  • Accessibility : Access using a custom domain name OSS Bucket, It is easier to access and share resources.

  • Persistence of links : Bind a custom domain name to ensure link persistence. Resources can still be accessed even if the storage location changes.

Restrictions on use

  • Binding Chinese domain names is not supported.

  • The domain name is not bound in image processing.

  • Each domain name can only be bound to one Bucket。

  • each Bucket Can bind at most one hundred Domain names.

  • adopt OSS When the management console binds a custom domain name, it is not allowed to bind a universal domain name (set the domain name prefix to *, so that all sub domain names of the main domain name point to Bucket Default domain name). adopt CDN accelerate OSS It is allowed to bind the universal domain name, but the domain name will not be OSS The management console displays.

  • The top-level domain name involved in the bound custom domain name must meet the requirements of the specified suffix, otherwise it will be regarded as an invalid domain name, which will eventually lead to the domain name binding failure. For more information, see Classification and resolution of top-level domain names

prerequisite

Operation steps

Step 1: Bind a custom domain name

According to the service provider of the domain name (available in Domain name information query (WHOIS) Page query) and the account (available in Cloud resolution DNS Console Query), refer to the corresponding steps to bind the domain name to OSS Bucket。

Bind the domain name registered by the current AliCloud account

Bind the domain name registered with the current AliCloud account to OSS Bucket The operation steps are as follows:

  1. Sign in OSS Management Console

  2. single click Bucket List , and then click Target Bucket name.

  3. In the left navigation bar, select Bucket Configuration > Domain name management

  4. stay Domain name management Page, click Bind domain name

  5. stay Bind domain name Panel, enter a custom domain name without a protocol, such as static.example.com , and then click Confirm Binding

    Custom Domain Name Example

    scene

    Domain Name Example

    describe

    Static website hosting

    example.com

    With the primary domain name, users can access the complete website content hosted on OSS through the primary domain name.

    Static resource service

    static.example.com

    Subdomain is used to centrally manage and provide static resources of the website (such as pictures, style sheets, scripts, etc.).

    Picture service

    images.example.com

    Use sub domain names to provide image resources for websites or mobile applications.

    Video storage and playback

    video.example.com

    Use sub domain names to store and quickly access video content.

    File sharing and downloading

    downloads.example.com

    Use sub domain name to provide convenient file download service.

    Backup and log storage

    backup.example.com

    The sub domain name is used to store backup data or log files and simplify the data management process.

    API document hosting

    docs.example.com

    The sub domain name is used to display API documents for developers to access.

  6. add to CNAME Record, the domain name will be customized static.example.com Resolve to bound Bucket The default Internet domain name of.

    Auto Add

    stay Bind domain name Panel, opening Automatically add CNAME records

     1.png

    After opening, Cloud resolution DNS Will automatically add a CNAME record. Examples are as follows: 1.png

    Add manually

    If not Bind domain name Panel, opening Automatically add CNAME records , you need to Cloud resolution DNS Console Add one manually CNAME Otherwise, the bound custom domain name will not take effect.

    1. Sign in Cloud resolution DNS Console

    2. stay Public network DNS analysis > Authoritative domain name resolution , click Resolution Settings

    3. single click Add Record , fill in the domain name resolution information.

      parameter

      explain

      Sample value

      Record Type

      choice CNAME Record the domain name resolution to another domain name

      CNAME

      Host record

      Fill in the prefix of the domain name to be bound.

      static

      Resolve request source

      The circuit used to resolve the domain name. Suggested choice default , the system will automatically select the best route.

      default

      Record value

      fill in Bucket Internet access domain name of. Bucket The structure of the domain name is <bucketname>.<endpoint> . Internet in different regions Endpoint, See OSS Region and access domain name

      examplebucket.oss-cn-hangzhou.aliyuncs.com

      TTL

      The update cycle of the domain name. Leave the default value.

      explain

      take effect TTL There is a certain delay in the time of. Please refer to the actual situation.

      ten minute

    4. single click determine

      When finished, Cloud resolution DNS There will be a CNAME record. Examples are as follows: 1.png

Bind domain names registered with other AliCloud accounts

AliCloud A The domain name registered by the account is bound to Alibaba Cloud B Of account number OSS Bucket The operation steps are as follows:

  1. Using AliCloud B Account, obtaining TXT Recorded host records and recorded values.

    1. Sign in OSS Management Console

    2. single click Bucket List , and then click Target Bucket name.

    3. In the left navigation bar, select Bucket Configuration > Domain name management

    4. stay Domain name management Page, click Bind domain name

    5. stay Bind domain name Panel, enter the Alibaba Cloud to be bound without a protocol A Custom domain name of the account, such as static.example.com , and then copy the Host record and Record value

      Custom Domain Name Example

      scene

      Domain Name Example

      describe

      Static website hosting

      example.com

      With the primary domain name, users can access the complete website content hosted on OSS through the primary domain name.

      Static resource service

      static.example.com

      Subdomain is used to centrally manage and provide static resources of the website (such as pictures, style sheets, scripts, etc.).

      Picture service

      images.example.com

      Use sub domain names to provide image resources for websites or mobile applications.

      Video storage and playback

      video.example.com

      Use sub domain names to store and quickly access video content.

      File sharing and downloading

      downloads.example.com

      Use sub domain name to provide convenient file download service.

      Backup and log storage

      backup.example.com

      The sub domain name is used to store backup data or log files and simplify the data management process.

      API document hosting

      docs.example.com

      The sub domain name is used to display API documents for developers to access.

  2. Using AliCloud A Account, adding TXT record.

    1. Sign in Cloud resolution DNS Console

    2. In the domain name resolution list, click Resolution Settings

    3. single click Add Record , fill in the domain name resolution information.

      parameter

      explain

      Sample value

      Record Type

      Select the type that the domain name points to as TXT。

      TXT

      Host record

      Alibaba Cloud resolution DNS The primary domain name has been automatically filled for you. Therefore, it is not necessary to fill in the main domain name manually.

      • If the main domain name is bound, fill in _dnsauth . For example, the domain name is example.com , fill in _dnsauth

      • If the binding is a subdomain name, fill in _Dnsauth.<domain name prefix> . For example, the domain name is static.example.com , fill in _dnsauth.static

      _dnsauth.static

      Resolve request source

      The circuit used to resolve the domain name. Suggested choice default , the system will automatically select the best route.

      default

      Record value

      Fill in Alibaba Cloud B Account acquired TXT In record CnameToken。

      b0d777f7ccddeae93358d908ed59****

      TTL

      The update cycle of the domain name. Leave the default value.

      explain

      take effect TTL There is a certain delay in the time of. Please refer to the actual situation.

      ten minute

    4. single click determine

  3. Using AliCloud B Account number, at OSS Console Bind domain name Panel, click Verify domain name ownership and bind

  4. Using AliCloud A Account, adding CNAME record.

    1. In the domain name resolution list, click Resolution Settings

    2. single click Add Record , fill in the domain name resolution information.

      parameter

      explain

      Sample value

      Record Type

      Select the type that the domain name points to as CNAME。

      CNAME

      Host record

      Fill in the host record according to the domain name prefix.

      • If it is a primary domain name, for example example.com , Enter @

      • If it is a sub domain name, enter the prefix of the domain name. For example, the domain name is static.example.com , Enter static。

      static

      Resolve request source

      The circuit used to resolve the domain name. Suggested choice default , the system will automatically select the best route.

      default

      Record value

      fill in Bucket Internet access domain name of. Bucket The structure of the domain name is <bucketname>.<endpoint> . Internet in different regions Endpoint, See OSS Region and access domain name

      examplebucket.oss-cn-hangzhou.aliyuncs.com

      TTL

      The update cycle of the domain name. Leave the default value.

      explain

      take effect TTL There is a certain delay in the time of. Please refer to the actual situation.

      ten minute

    3. single click determine

Bind domain names registered with non Alibaba Cloud accounts

Bind domain names registered with other domain name service providers to OSS Bucket The operation steps are as follows:

  1. In Alibaba Cloud OSS, generate TXT Recorded host records and recorded values.

    1. Sign in OSS Management Console

    2. single click Bucket List , and then click Target Bucket name.

    3. In the left navigation bar, select Bucket Configuration > Domain name management

    4. stay Domain name management Page, click Bind domain name

    5. stay Bind domain name Panel, enter the domain name registered with other domain name service providers without agreement, such as static.example.com , and then copy the Host record and Record value

      Custom Domain Name Example

      scene

      Domain Name Example

      describe

      Static website hosting

      example.com

      With the primary domain name, users can access the complete website content hosted on OSS through the primary domain name.

      Static resource service

      static.example.com

      Subdomain is used to centrally manage and provide static resources of the website (such as pictures, style sheets, scripts, etc.).

      Picture service

      images.example.com

      Use sub domain names to provide image resources for websites or mobile applications.

      Video storage and playback

      video.example.com

      Use sub domain names to store and quickly access video content.

      File sharing and downloading

      downloads.example.com

      Use sub domain name to provide convenient file download service.

      Backup and log storage

      backup.example.com

      The sub domain name is used to store backup data or log files and simplify the data management process.

      API document hosting

      docs.example.com

      The sub domain name is used to display API documents for developers to access.

  2. In the domain name service provider's DNS Analytic platform, please refer to the table below to add TXT record.

    parameter

    explain

    Sample value

    Record Type

    Select the type that the domain name points to as TXT。

    TXT

    Host record

    If another domain name service provider's DNS The resolution platform has automatically filled in the main domain name for you. When filling in, you do not need to manually fill in the main domain name.

    • If the main domain name is bound, fill in _dnsauth . For example, the domain name is example.com , fill in _dnsauth

    • If the binding is a subdomain name, fill in _Dnsauth.<domain name prefix> . For example, the domain name is static.example.com , fill in _dnsauth.static

    _dnsauth.static

    Record value

    Fill in from AliCloud OSS Acquired TXT In record CnameToken。

    b0d777f7ccddeae93358d908ed59****

  3. In Alibaba Cloud OSS Console Bind domain name Panel, click Verify domain name ownership and bind

  4. In the domain name service provider's DNS Analytic platform, please refer to the table below to add CNAME record.

    parameter

    explain

    Sample value

    Record Type

    Select the type that the domain name points to as CNAME。

    CNAME

    Host record

    Fill in the host record according to the domain name prefix.

    • If it is a primary domain name, for example example.com , Enter @

    • If it is a sub domain name, enter the domain name prefix. For example, the domain name is static.example.com , Enter static。

    static

    Record value

    fill in Bucket Internet access domain name of. Bucket The structure of the domain name is <bucketname>.<endpoint> . Internet in different regions Endpoint, See OSS Region and access domain name

    examplebucket.oss-cn-hangzhou.aliyuncs.com

Step 2: Verify the custom domain name

After binding the user-defined domain name, when the user initiates a request through the user-defined domain name, the request will be resolved to the bucket default domain name through DNS. You can use nslookup or dig Command to verify whether the custom domain name resolution is effective.

nslookup

take static.example.com Replace with the domain name you want to query, and then execute the following command.

 nslookup -type=CNAME static.example.com

Domain name resolution results display bound Bucket Internet access domain name of, indicating that the custom domain name resolution has taken effect.

 1.png

dig

take static.example.com Replace with the domain name you want to query, and then execute the following command.

 dig CNAME static.example.com

Domain name resolution results display bound Bucket Internet access domain name of, indicating that the custom domain name resolution has taken effect.

 2.png

Step 3: Use a custom domain name

After the custom domain name resolution takes effect, you can use the HTTP The protocol and custom domain name structure contain the signature and validity URL,URL The format of is http://YourDomain/ObjectName? Signature parameters , and then use the URL visit OSS File.

  1. Get pre signature URL。

    use OSS Console

    1. Sign in OSS Management Console

    2. single click Bucket list , and then click Target Bucket name.

    3. In the left navigation bar, select file management > File List

    4. On the file list page, click the target file name.

    5. stay details Panel Own domain name , select the bound custom domain name, keep the other default values, and then click Copy File URL

       image

    Use graphical management tools ossbrowser

    ossbrowser support Object Level operations are similar to those supported by the console. Please follow ossbrowser Interface guidance is completed to obtain pre signature URL Operation of. How to download ossbrowser, See Graphical management tool Ossbrowser 2.0 (preview version)

    1. Log in with a custom domain name ossbrowser。

       image

    1. get files URL。

       1.png

    Using AliCloud SDK

    New using custom domain name OssClient And generate pre signature URL。

    Java

     import com.aliyun.oss.*; import com.aliyun.oss.common.auth.*; import com.aliyun.oss.common.comm.SignVersion; import com.aliyun.oss.model.GeneratePresignedUrlRequest; import java.net.URL; import java.util.Date; public class Demo { public static void main(String[] args) throws Throwable { // yourCustomEndpoint Please fill in your custom domain name. for example http://static.example.com  String endpoint = "yourCustomEndpoint"; //Please fill in the Region Information, such as cn-hangzhou String region = "cn-hangzhou"; //Fill in Bucket Name, for example examplebucket。 String bucketName = "examplebucket"; //Fill in Object Full path, such as exampleobject.txt。 Object The full path cannot contain Bucket name. String objectName = "exampleobject.txt"; //Get access credentials from environment variables. Please configure the environment variables before running this code example EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider(); //Create OSSClient example. //When OSSClient When the instance is no longer used, call shutdown Method to free resources. ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration(); //Note that the settings true open CNAME option clientBuilderConfiguration.setSupportCname(true); //Explicitly declare using the V4 signature algorithm clientBuilderConfiguration.setSignatureVersion(SignVersion.V4); OSS ossClient = OSSClientBuilder.create() .endpoint(endpoint) .credentialsProvider(credentialsProvider) .clientConfiguration(clientBuilderConfiguration) .region(region) .build(); try { //Specify the generated pre signature URL Expiration time, in milliseconds. This example sets the expiration time to one For example, hours. Date expiration = new Date(new Date().getTime() + 3600 * 1000L); //Generate pre signature URL。 GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucketName, objectName, HttpMethod.GET); //Set expiration time. request.setExpiration(expiration); //Via HTTP GET Request to generate pre signature URL。 URL signedUrl = ossClient.generatePresignedUrl(request); //Print pre signature URL。 System.out.println("signed url for getObject: " + signedUrl); } catch (OSSException oe) { System.out.println("Caught an OSSException, which means your request made it to OSS, " + "but was rejected with an error response for some reason."); System.out.println("Error Message:" + oe.getErrorMessage()); System.out.println("Error Code:" + oe.getErrorCode()); System.out.println("Request ID:" + oe.getRequestId()); System.out.println("Host ID:" + oe.getHostId()); } catch (ClientException ce) { System.out.println("Caught an ClientException, which means the client encountered " + "a serious internal problem while trying to communicate with OSS, " + "such as not being able to access the network."); System.out.println("Error Message:" + ce.getMessage()); } finally { if (ossClient != null) { ossClient.shutdown(); } } } }

    Python

     # -*- coding: utf-8 -*- import oss2 from oss2.credentials import EnvironmentVariableCredentialsProvider #Get access credentials from environment variables. Before running this code example, make sure that the environment variable has been set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET。 auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider()) #Fill in Endpoint Corresponding Region Information, such as cn-hangzhou。 be careful, v4 Under signature, this parameter must be filled in region = "cn-hangzhou" #Fill in the custom domain name, for example static.example.com。 endpoint = ' http://static.example.com ' # yourBucketName Fill in the name of the storage space. bucket = oss2.Bucket(auth, endpoint, "yourBucketName", region=region, is_cname=True) #Fill in Object Full path, such as exampledir/exampleobject.txt。 Object The full path cannot contain Bucket name. object_name = 'exampledir/exampleobject.txt' #Generate pre signature of downloaded files URL, Valid for six hundred Seconds. #Generate pre signature URL When, OSS By default Object The forward slash (/) in the full path is escaped, resulting in the generated pre signature URL It cannot be used directly. #Settings slash_safe by True,OSS No Object The forward slash (/) in the full path is escaped, and the generated pre signature URL It can be used directly. url = bucket.sign_url('GET', object_name, 600, slash_safe=True, params=params) Print ('pre signature URL The address of is: ', url)

    Node.js

     const OSS = require("ali-oss"); //Define a function to generate a pre signed URL async function generateSignatureUrl(fileName) { //Get pre signature URL const client = await new OSS({ //Use custom domain name as Endpoint。 endpoint: ' http://static.example.com ',  //Get access credentials from environment variables. Before running this code example, make sure that the environment variable has been set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET。 accessKeyId: process.env.OSS_ACCESS_KEY_ID, accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET, bucket: 'examplebucket', // yourregion fill in Bucket Location. East China 1 (Hangzhou) as an example, Region Fill in as oss-cn-hangzhou。 region: 'oss-cn-hangzhou', authorizationV4: true, cname: true }); return await client.signatureUrlV4('GET', 3600, { Headers: {}//Please set the request header here according to the actual sent request header }, fileName); } //Call the function and pass in the file name generateSignatureUrl('yourFileName').then(url => { console.log('Generated Signature URL:', url); }).catch(err => { console.error('Error generating signature URL:', err); });

    PHP

     <?php if (is_file(__DIR__ . '/../autoload.php')) { require_once __DIR__ . '/../autoload.php'; } if (is_file(__DIR__ . '/../vendor/autoload.php')) { require_once __DIR__ . '/../vendor/autoload.php'; } use OSS\OssClient; use OSS\Core\OssException; use OSS\Http\RequestCore; use OSS\Http\ResponseCore; use OSS\Credentials\EnvironmentVariableCredentialsProvider; //Get access credentials from environment variables. Before running this code example, make sure that the environment variable has been set OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET。 $provider = new EnvironmentVariableCredentialsProvider(); // yourEndpoint fill in Bucket Corresponding to the region Endpoint。 East China 1 (Hangzhou) as an example, Endpoint Fill in as http://static.example.com  $endpoint = " http://static.example.com "; //Fill in Bucket name. $bucket= "examplebucket"; //Filling does not include Bucket Name included Object Full path. $object = "exampleobject.txt"; //Specify pre signature URL Expires on 600s (up to 32400s)。 $timeout = 600; try { $config = array(   "provider" => $provider, "endpoint" => $endpoint, 'signatureVersion'=>OssClient::OSS_SIGNATURE_VERSION_V4, "cname"	=> true, "region"=> "cn-hangzhou" ); $ossClient = new OssClient($config); //Generate pre signature URL。 $signedUrl = $ossClient->signUrl($bucket, $object, $timeout, "GET"); print_r($signedUrl); } catch (OssException $e) { printf(__FUNCTION__ . ": FAILED\n"); printf($e->getMessage() . "\n"); return; }

    Go

     package main import ( "context" "flag" "log" "time" "github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss" "github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials" ) //Defining Global Variables var ( Region string//Storage area BucketName string//The name of the storage space ObjectName string//Object name ) // init Function to initialize command line parameters func init() { flag.StringVar(&region, "region", "", "The region in which the bucket is located.") flag.StringVar(&bucketName, "bucket", "", "The name of the bucket.") flag.StringVar(&objectName, "object", "", "The name of the object.") } func main() { //Resolve command line parameters flag.Parse() //Check bucket Whether the name is empty if len(bucketName) == 0 { flag.PrintDefaults() log.Fatalf("invalid parameters, bucket name required") } //Check region Is it empty if len(region) == 0 { flag.PrintDefaults() log.Fatalf("invalid parameters, region required") } //Check object Whether the name is empty if len(objectName) == 0 { flag.PrintDefaults() log.Fatalf("invalid parameters, object name required") } //Load the default configuration and set the credential provider and region cfg := oss.LoadDefaultConfig(). WithCredentialsProvider(credentials.NewEnvironmentVariableCredentialsProvider()). WithRegion(region). WithEndpoint(" http://static.example.com "). WithUseCName(true) //Create OSS client client := oss.NewClient(cfg) //Build GetObject Pre signature of URL result, err := client.Presign(context.TODO(), &oss.GetObjectRequest{ Bucket: oss.Ptr(bucketName), Key:    oss.Ptr(objectName), //RequestPayer: oss.Ptr("requester"), //Specify the identity of the requester }, oss.PresignExpires(10*time.Minute), ) if err ! = nil { log.Fatalf("failed to get object presign %v", err) } log.Printf("request method:%v\n", result.Method) log.Printf("request expiration:%v\n", result.Expiration) log.Printf("request url:%v\n", result.URL) if len(result.SignedHeaders) > 0 { //Use pre signature when the returned result contains pre signature header URL send out GET The request also contains the corresponding request header to avoid inconsistency, which may lead to request failure and pre signature error log.Printf("signed headers:\n") for k, v := range result.SignedHeaders { log.Printf("%v: %v\n", k, v) } } }

    Using Command Line Tools ossutil

    Use a custom domain name through Presign URL) Pre signature of command generation file URL。

     ossutil presign  oss://examplebucket/exampleobject.txt  --endpoint " http://static.example.com ” --addressing-style "cname"

    if need ossutil The command automatically uses the custom domain name, instead of manually specifying the custom domain name in the command each time, you can use the configuration file Add a custom domain name in,

  2. Access pre signature in browser URL。

     2023-11-07_11-01-40.png

relevant API

Subsequent operations

adopt HTTPS Protocol Access OSS file

The custom domain name is not configured SSL In the case of certificates, it is not supported by default HTTPS Protocol access. adopt HTTPS When the protocol accesses the custom domain name, the browser will display an insecure connection warning. To pass HTTPS Protocol Access OSS File, you need to customize the domain name Configure Certificate

 httpsandpresigned

Use long-term valid without signature URL visit OSS file

warning

To obtain the URL, I.e URL The format of is http://YourDomainName/ObjectName , you need to set the file as public read. After it is set to public reading, any user on the Internet can access the file, which may result in the leakage of your data and sharp increase in costs. It is recommended that you use the URL。

You can set the file as public read in the following two ways:

  • Set the file as public read : Set the permissions of OSS files to public read. In this case, the URL of the file will not be valid, and anyone can access it. To prevent files from being stolen by other websites, you need to configure them in OSS Anti-theft chain

  • CDN accelerate OSS resources : Keep OSS file permissions private and provide public read access through CDN. In this case, the URL of the file will not be valid, and anyone can access it. To prevent files from being stolen by other websites, you need to configure them on the CDN Anti-theft chain

 https

prevent OSS Files are stolen by other websites

By default, any website can display your OSS File, which may result in additional request fees and downlink traffic fees. You can use the Anti-theft chain , setting Referer Blacklist or whitelist to restrict access sources. After the immobilizer is configured, unauthorized websites will not be able to display your OSS At the same time, failed requests will not incur request fees and downlink traffic fees.

 Anti-theft chain

use OSS Hosting static websites

If you use OSS As a server for static websites, it directly stores and provides static files (such as HTML、CSS、JavaScript ) so that users can access these contents through the Internet. In addition to binding a custom domain name, you also need to Bucket set up Static website hosting

 one

promote OSS File download speed in different regions

The files in the OSS bucket are stored in a region (such as Hangzhou). To improve the speed of downloading OSS files for users in different regions, you can use the CDN accelerate OSS . ON CDN After acceleration, OSS files will be distributed to CDN cache nodes in all regions. When users access files, they can obtain content from cache nodes closer to them, thus effectively improving the download speed.

explain

When using CDN to accelerate OSS, it is recommended to use the CDN domain name for file download. For file upload, you can continue to use the original bucket default domain name.

 image

promote OSS Long distance file transmission speed

The files in the OSS bucket are stored in a region (such as Hangzhou). When non mainland users visit, the upload and download experience may be very poor due to the long transmission distance. To improve the long-distance transmission speed of OSS files, you can enable Transmission acceleration , bind the custom domain name to the OSS transport acceleration domain name instead of Bucket Default domain name.

 one

common problem

Set Content-Disposition: inline , cannot preview

To ensure data transmission security, use OSS Of Bucket Default domain name( <bucketName>.oss-<regionId>.aliyuncs.com )Or transport acceleration domain name( <bucketName>.oss-accelerate.aliyuncs.com )When accessing files, OSS The download response header will be forced to be added( x-oss-force-download: true and Content-Disposition: attachment )。 Browser detected Content-Disposition: attachment The download is forced when. use OSS When a domain name accesses a file, the request process is as follows:

 2.png

You can use the registered domain name (for example Example. com) static.example.com), And bind it to Bucket, Then use the custom domain name to access the file. At this point, OSS The download response header will not be forced to be added in the return. because OSS No settings Content-Disposition Field, the browser will MIME The type automatically determines the processing method. For most common file types, the browser will directly display the file content instead of downloading it.

 1.png

Selection not supported OSS What about cloud services for filing?

For direct use of AliCloud OSS Users hosting static websites because OSS The service does not support filing. You can take the following steps to meet the filing requirements:

  1. Purchase for filing server: It is recommended that you purchase one with minimum configuration and minimum duration three Months ECS example , for example ECS 99 Package To meet the filing conditions.

  2. Filing: use this ECS The corresponding record operation is performed for the instance.

  3. Use the registered domain name: After the registration is successful, you can point the domain name to Alibaba Cloud OSS, Realize the hosting of static websites.

Existing host record and current addition CNAME The host records generated by the records are the same, and cannot be automatically added temporarily CNAME record

reason

When the existing host record matches the current automatically added CNAME When the records are the same, there may be the following situations:

  • Conflict record: A record using the same host record already exists, but the record type may be the same as CNAME Different. For example, there may already be a A record.

  • Duplicate record: a record using the same host record already exists, and the record type is CNAME record. This may be because the same record has been manually added previously.

Solution

In this case, you can use Alibaba Cloud Cloud resolution DNS Console Decide how to handle according to your needs:

  • If you want to keep the existing conflict or duplicate host records, you can re customize a sub domain name for binding.

  • If you do not want to keep the existing host records:

    • If it is a conflict record, you can delete it and then create CNAME Record resolution to Bucket Domain name.

    • If it is a duplicate record, you can modify the record and resolve it to Bucket Domain name.

The domain name is bound to another Bucket What should we do?

The domain name is bound to another Bucket Yes, there are two solutions:

  • Customize a subdomain name. For example, OSS Tips oss.example.com Has been Bucket Yes, you can customize a subdomain name, such as static.example.com, Then bind the new subdomain name.

  • Rebind. For example, OSS Tips oss.example.com Has been Bucket Is bound. You need to unbind the Bucket, Then rebind to the current Bucket On.

    How to cancel Bucket Bound domain name

    1. If enabled CDN Acceleration, need to close first CDN Accelerate.

      You need to modify CDN The origin information of the acceleration service, so that the acceleration domain name no longer points to OSS Of Bucket Domain name. See Configure Origin

    2. Unbind the custom domain name.

      1. Sign in OSS Management Console

      2. single click Bucket List , and then click Target Bucket name.

      3. In the left navigation bar, select Bucket to configure > Domain name management

      4. In the domain name list, click Domain name binding configuration

      5. stay Domain name binding configuration Panel, click Unbind Then click determine

    3. Delete domain name resolution.

      After unbinding the custom domain name, you need to manually delete the configured TXT Parsing records and CNAME Parse records. See Delete Record

NeedVerifyDomainOwnership

After binding the custom domain name, the file cannot be previewed?

If you bind a custom domain name and CNAME After the resolution takes effect, the file cannot be previewed. Please check the following settings:

set up

Abnormal causes

resolvent

OSS

Content-Type The value of is inconsistent with the actual file type. The browser cannot parse and render the file correctly, and can only treat it as a download file.

Set reasonable Content-Type。 See How to set Content-Type(MIME)?

Content-Disposition Is set to attachment . Browser detected Content-Disposition: attachment The download behavior is triggered when the.

take Content-Disposition Set to inline . For specific steps, see Manage file metadata

CDN

The cache resource was not refreshed.

Refresh CDN Cache resources. For specific steps, see Refresh and preheat resources

browser

Preview of files in this format is not supported, such as. doc,. ppt,. pdf,. mov File.

  • Install plug-ins for your browser to support previewing files in this format.

  • It is not necessary to install plug-ins for the browser. For. doc,. ppt,. pdf And other office documents WebOffice Online Preview Process to support previewing files in this format.

  • You do not need to install plug-ins for your browser. For. mov And other video files Video transcoding Process to support previewing files in this format.

It has been resolved to WAF The domain name with content can be bound to Bucket Is it?

It can be bound normally. WAF Parsing and CNAME Resolution will not conflict because they are resolved and operated at different levels. How to WAF Access OSS, See CDN Back to source OSS private Bucket Serial connection in the scene WAF Best Practices

After binding the custom domain name, the previous file URL Can I continue to use it?

Can continue to use. How to get previous files URL, See Use pre pre signature URL Download files

Is using a custom domain name public access?

It is generally accessed through the public network. Public network users usually need to access your OSS File, so the custom domain name is resolved to Bucket Internet access domain name of.

How to access with a custom domain name OSS Is the file downloading behavior?

To access with a custom domain name OSS File is a download behavior, you can Content-Disposition Set to attachment . See How to configure access through a custom domain name OSS Does the file realize forced download?

Domain name resolution is configured, but does it not take effect?

Could be local DNS Cache, you can use the following command to clear DNS Cache, and then try to access.

Window

 ipconfig /flushdns

macOS

 sudo dscacheutil -flushcache;  sudo killall -HUP mDNSResponder

Linux

 sudo systemd-resolve --flush-caches

Why are you using <video> Label, if the server is set Content-Disposition: attachment , some browsers still choose to play videos instead of downloading them?

use <video> When tagging, the browser will actively request the video stream and give priority to the MIME type. If the MIME type returned by the server is suitable for playback (such as video/mp4 ), the browser will choose to play, but ignore Content-Disposition: attachment Indication of.