Tous les produits
Search
Centre de documentation

Object Storage Service:Hébergement de site web statique (SDK Ruby)

Dernière mise à jour :Aug 18, 2026

Vous pouvez configurer l'hébergement de site web statique pour un bucket Object Storage Service (OSS). Une fois la configuration appliquée, accédez au site directement via le nom de domaine du bucket. Vous serez alors redirigé vers la page d'index ou la page d'erreur définie pour le site hébergé.

Configurer l'hébergement de site web statique

L'exemple de code suivant montre comment configurer l'hébergement de site web statique :

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  # In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint. 
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
  # The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
  access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')

# Specify the name of the bucket. Example: examplebucket. 
bucket = client.get_bucket('examplebucket')
# Replace index.html with your default homepage for statistic website hosting. 
# Replace error.html with the default 404 page for static website hosting. 
bucket.website = Aliyun::OSS::BucketWebsite.new(index: 'index.html', error: 'error.html')

Interroger les configurations d'hébergement de site web statique

L'exemple de code suivant montre comment interroger les configurations d'hébergement de site web statique :

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  # In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint. 
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
  # The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
  access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')

# Specify the name of the bucket. Example: examplebucket. 
bucket = client.get_bucket('examplebucket')
# Query the static website hosting configurations. 
web = bucket.website
puts web.to_s

Supprimer les configurations d'hébergement de site web statique

L'exemple de code suivant montre comment supprimer les configurations d'hébergement de site web statique :

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  # In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint. 
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
  # The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
  access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')

# Specify the name of the bucket. Example: examplebucket. 
bucket = client.get_bucket('examplebucket')
# Delete the static website hosting configurations. 
bucket.website = Aliyun::OSS::BucketWebsite.new(enable: false)

Références

  • Pour plus d'informations sur l'opération API permettant de configurer l'hébergement de site web statique, consultez PutBucketWebsite.

  • Pour plus d'informations sur l'opération API permettant d'interroger les configurations d'hébergement de site web statique, consultez GetBucketWebsite.

  • Pour plus d'informations sur l'opération API permettant de supprimer les configurations d'hébergement de site web statique, consultez DeleteBucketWebsite.