Todos os produtos
Search
Central de documentação

Object Storage Service:Static website hosting (Ruby SDK)

Última atualização: Jul 03, 2026

Você pode configurar a hospedagem de site estático para um bucket do Object Storage Service (OSS). Após a aplicação das configurações, acesse o site diretamente pelo nome de domínio do bucket. Nesse caso, você será redirecionado para a página inicial ou de erro especificada na hospedagem.

Configure hospedagem de site estático

O exemplo de código a seguir mostra como configure a hospedagem de site estático:

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')

Consultar configurações de hospedagem de site estático

O exemplo de código a seguir mostra como consultar as configurações de hospedagem de site estático:

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

Exclua configurações de hospedagem de site estático

O exemplo de código a seguir mostra como exclua as configurações de hospedagem de site estático:

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)

Referências

  • Para obter mais informações sobre a operação de API usada para configure a hospedagem de site estático, consulte PutBucketWebsite.

  • Para obter mais informações sobre a operação de API usada para consultar as configurações de hospedagem de site estático, consulte GetBucketWebsite.

  • Para obter mais informações sobre a operação de API usada para exclua as configurações de hospedagem de site estático, consulte DeleteBucketWebsite.