Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Yandex Object Storage
    • All tutorials
      • Setting up hosting
      • Support for your own domain
      • Support for multiple domain names
      • Configuring HTTPS
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Bucket logs
  • Release notes
  • FAQ

In this article:

  • Static website hosting
  • Redirects for all requests
  • Conditional request redirects
  1. Step-by-step tutorials
  2. Hosting static websites
  3. Setting up hosting

Setting up hosting

Written by
Yandex Cloud
Improved by
Tania L.
Updated at May 5, 2025
  • Static website hosting
  • Redirects for all requests
  • Conditional request redirects

You can host your static website in Object Storage. A static website is based on such client-side technologies as HTML, CSS, or JavaScript. It may not contain any scripts that run on the web server side.

In a static website, pages are objects in a bucket, where object keys match the website page paths, and the full URL of a page has http(s)://website.yandexcloud.net/<bucket_name>/<object_key> format.

Object Storage buckets support:

  • Static website hosting.
  • Redirects for all requests.
  • Conditional request redirects.

Static website hostingStatic website hosting

Management console
Yandex Cloud CLI
Terraform
API
  1. In the management console, select Object Storage from the list of services and go to the bucket you want to configure hosting for.
  2. In the left-hand panel, select Settings.
  3. Navigate to the General tab.
  4. Enable public access to bucket operations.
  5. Click Save.
  6. Select the Website tab.
  7. Under Hosting:
    • In the Home page field, specify the absolute path to the file in the bucket for the website home page, e.g., index.html.

      Warning

      The key of the object containing your website homepage must not include the / character.

    • Optionally, in the Error page field, specify the absolute path to the file in the bucket to show for 4xx errors, e.g., pages/error404.html. By default, Object Storage returns its own page.

  8. Click Save.

Use the link in Link to check the hosting.

If you do not have the Yandex Cloud CLI yet, install and initialize it.

The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID> command. You can specify a different folder using the --folder-name or --folder-id parameter.

  1. See the description of the CLI command for setting up static website hosting in a bucket:

    yc storage bucket update --help
    
  2. Create a hosting configuration file in JSON format. Here is an example:

    {
      "index": "index.html",
      "error": "error404.html"
    }
    

    Where:

    • index: Absolute path to the website home page file.

      Warning

      The key of the object containing your website homepage must not include the / character.

    • error: Absolute path to the file the user will see in case of 4xx errors.

  3. Run this command:

    yc storage bucket update --name <bucket_name> \
      --website-settings-from-file <path_to_file>
    

    Where:

    • --name: Bucket name.
    • --website-settings-from-file: Path to the hosting configuration file.

    Result:

    name: my-bucket
    folder_id: b1gjs8dck8bv********
    default_storage_class: STANDARD
    versioning: VERSIONING_SUSPENDED
    max_size: "10737418240"
    acl: {}
    created_at: "2022-12-14T08:42:16.273717Z"
    

To make sure the bucket description now contains the hosting settings, run this command:

yc storage --name <bucket_name> bucket get --full

Result:

website_settings:
  index: index.html
  error: error404.html
  redirect_all_requests: {}

Note

Terraform uses a service account to interact with Object Storage. Assign to the service account the required role, e.g., storage.admin, for the folder where you are going to create resources.

If you do not have Terraform yet, install it and configure its Yandex Cloud provider.

Before you start, retrieve the static access keys: a secret key and key ID used for Object Storage authentication.

Note

In addition to static access keys, you can use an IAM token for authentication in Object Storage. For more details, see Creating a bucket and the relevant provider documentation.

  1. In the configuration file, define the parameters of the resources you want to create:

    provider "yandex" {
      token     = "<OAuth>"
      cloud_id  = "<cloud_ID>"
      folder_id = "<folder_ID>"
      zone      = "ru-central1-a"
    }
    
    resource "yandex_iam_service_account" "sa" {
      name = "<service_account_name>"
    }
    
    // Assigning a role to a service account
    resource "yandex_resourcemanager_folder_iam_member" "sa-admin" {
      folder_id = "<folder_ID>"
      role      = "storage.admin"
      member    = "serviceAccount:${yandex_iam_service_account.sa.id}"
    }
    
    // Creating a static access key
    resource "yandex_iam_service_account_static_access_key" "sa-static-key" {
      service_account_id = yandex_iam_service_account.sa.id
      description        = "static access key for object storage"
    }
    
    resource "yandex_storage_bucket" "test" {
      access_key = yandex_iam_service_account_static_access_key.sa-static-key.access_key
      secret_key = yandex_iam_service_account_static_access_key.sa-static-key.secret_key
      bucket     = "<bucket_name>"
      acl        = "public-read"
    
      website {
        index_document = "index.html"
        error_document = "error.html"
      }
    
    }
    

    Where:

    • access_key: Static access key ID.
    • secret_key: Secret access key value.
    • bucket: Bucket name.
    • acl: ACL access management parameters.
    • website: Website parameters:
      • index_document: Absolute path to the website home page file. This is a required parameter.

        Warning

        The key of the object containing your website homepage must not include the / character.

      • error_document: Absolute path to the file the user will see in case of 4xx errors. This is an optional parameter.

  2. Make sure the configuration files are correct.

    1. In the command line, go to the directory where you created the configuration file.

    2. Run a check using this command:

      terraform plan
      

    If you described the configuration correctly, the terminal will display a list of the resources being created and their parameters. If the configuration contains any errors, Terraform will point them out.

  3. Deploy the cloud resources.

    1. If the configuration does not contain any errors, run this command:
    terraform apply
    
    1. Confirm creating the resources.

    This will create all the resources you need in the specified folder. You can check the new resources and their settings using the management console.

To set up static website hosting, use the update REST API method for the Bucket resource, the BucketService/Update gRPC API call, or the upload S3 API method.

Redirects for all requestsRedirects for all requests

Management console
Yandex Cloud CLI
Terraform
API
  1. In the management console, select Object Storage from the list of services and go to the bucket you want to configure request redirects for.
  2. In the left-hand panel, select Settings.
  3. Select the Website tab.
  4. Under Redirect, specify:
    • Domain name of the host to act as the redirect target for all requests to the bucket.
    • Optionally, Protocol if the specified host accepts requests only over a specific protocol.
  5. Click Save.

If you do not have the Yandex Cloud CLI yet, install and initialize it.

The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID> command. You can specify a different folder using the --folder-name or --folder-id parameter.

  1. See the description of the CLI command for setting up redirects for all requests:

    yc storage bucket update --help
    
  2. Create a redirect configuration file in JSON format. For example:

    {
      "redirectAllRequests": {
        "protocol": "PROTOCOL_HTTP",
        "hostname": "example.com"
      }
    }
    

    Where:

    • protocol: Data transfer protocol, PROTOCOL_HTTP or PROTOCOL_HTTPS. By default, the original request protocol is used.
    • hostname: Domain name of the host to act as the redirect target for all requests to the current bucket.
  3. Run this command:

    yc storage bucket update --name <bucket_name> \
      --website-settings-from-file <path_to_file>
    

    Where:

    • --name: Bucket name.
    • --website-settings-from-file: Path to the redirect configuration file.

    Result:

    name: my-bucket
    folder_id: b1gjs8dck8bv********
    default_storage_class: STANDARD
    versioning: VERSIONING_SUSPENDED
    max_size: "10737418240"
    acl: {}
    created_at: "2022-12-14T08:42:16.273717Z"
    

With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.

Terraform is distributed under the Business Source License. The Yandex Cloud provider for Terraform is distributed under the MPL-2.0 license.

For more information about the provider resources, see the documentation on the Terraform website or mirror website.

If you do not have Terraform yet, install it and configure its Yandex Cloud provider.

To set up a redirect for all requests:

  1. Open the Terraform configuration file and add the redirect_all_requests_to parameter to the yandex_storage_bucket resource description:

    ...
    resource "yandex_storage_bucket" "test" {
      access_key = "<static_key_ID>"
      secret_key = "<secret_key>"
      bucket     = "<bucket_name>"
      acl        = "public-read"
    
      website {
        index_document = "<absolute_path_to_website_home_page_file>"
        error_document = "<absolute_path_to_error_file>"
        redirect_all_requests_to = "<host_name>"
      }
    }
    ...
    

    Where:

    • access_key: Static access key ID.

      Note

      In addition to static access keys, you can use an IAM token for authentication in Object Storage. For more details, see Creating a bucket and the relevant provider documentation.

    • secret_key: Secret access key value.

    • bucket: Bucket name.

    • acl: ACL access management parameters.

    • website: Website parameters:

      • index_document: Absolute path to the website home page file. This is a required parameter.
      • error_document: Absolute path to the file the user will see in case of 4xx errors. This is an optional parameter.
      • redirect_all_requests_to: Domain name of the host to act as the redirect target for all requests to the current bucket. You can specify a protocol prefix (http:// or https://). By default, the original request protocol is used.

    For more information about the yandex_storage_bucket resource parameters in Terraform, see this TF provider article.

  2. Check the configuration using this command:

    terraform validate
    

    If the configuration is correct, you will get this message:

    Success! The configuration is valid.
    
  3. Run this command:

    terraform plan
    

    The terminal will display a list of resources with their parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.

  4. Apply the configuration changes:

    terraform apply
    
  5. Confirm the changes: type yes into the terminal and press Enter.

    You can use the management console to check the request redirect settings.

To set up redirects for all requests to a bucket, use the update REST API method for the Bucket resource, the BucketService/Update gRPC API call, or the upload S3 API method.

Request redirects from HTTP to HTTPS are enabled automatically once you set up HTTPS access to a bucket. No other settings are required.

Conditional request redirectsConditional request redirects

With routing rules, you can redirect requests based on the object name prefixes or HTTP response codes. This enables you to redirect object requests to different web pages (if the object was removed) or redirect the requests that return errors.

Management console
Yandex Cloud CLI
Terraform
API
  1. In the management console, select Object Storage from the list of services and go to the bucket you want to configure conditional request redirects for.
  2. In the left-hand panel, select Settings.
  3. Select the Website tab.
  4. In Hosting, under Redirect, click Add forwarding rule.
  5. Under Condition, specify at least one condition for redirects:
    • Response code: HTTP code that Object Storage would have returned for the request without a redirect.
    • Key prefix: Object key prefix in the request. You can learn more about keys and how static websites work here.
  6. Under Redirect, set the following redirect parameters:
    • Protocol to use for sending redirected requests.
    • Domain name of the host to which all requests meeting the specified condition will be redirected.
    • Response code to determine the redirect type.
    • Replace key: None, Whole key, or Prefix only, specified in the condition.
  7. Click Save.

If you do not have the Yandex Cloud CLI yet, install and initialize it.

The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID> command. You can specify a different folder using the --folder-name or --folder-id parameter.

  1. See the description of the CLI command for setting up conditional request redirects:

    yc storage bucket update --help
    
  2. Create a conditional redirect configuration file in JSON format. Here is an example:

    {
      "routingRules": [
        {
          "condition": {
            "httpErrorCodeReturnedEquals": "404",
            "keyPrefixEquals": "key"
          },
          "redirect": {
            "hostname": "example.com",
            "httpRedirectCode": "301",
            "protocol": "PROTOCOL_HTTP",
            "replaceKeyPrefixWith": "prefix",
            "replaceKeyWith": "key"
          } 
        }
      ]
    }
    

    Where:

    • condition: Condition to trigger a redirect:

      • httpErrorCodeReturnedEquals: HTTP response code.
      • keyPrefixEquals: Object key prefix.
    • redirect: Redirect settings:

      • hostname: Domain name of the host to act as the redirect target for all requests to the current bucket.
      • httpRedirectCode: New HTTP response code.
      • protocol: New data transfer protocol, PROTOCOL_HTTP or PROTOCOL_HTTPS. By default, the original request protocol is used.
      • replaceKeyPrefixWith: New object key prefix.
      • replaceKeyWith: New object key.
  3. Run this command:

    yc storage bucket update --name <bucket_name> \
      --website-settings-from-file <path_to_file>
    

    Where:

    • --name: Bucket name.
    • --website-settings-from-file: Path to the conditional redirect configuration file.

    Result:

    name: my-bucket
    folder_id: b1gjs8dck8bv********
    default_storage_class: STANDARD
    versioning: VERSIONING_SUSPENDED
    max_size: "10737418240"
    acl: {}
    created_at: "2022-12-14T08:42:16.273717Z"
    

With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.

Terraform is distributed under the Business Source License. The Yandex Cloud provider for Terraform is distributed under the MPL-2.0 license.

For more information about the provider resources, see the documentation on the Terraform website or mirror website.

If you do not have Terraform yet, install it and configure its Yandex Cloud provider.

To set up conditional request redirects:

  1. Open the Terraform configuration file and add the routing_rules parameter to the bucket description:

    ...
    resource "yandex_storage_bucket" "test" {
      access_key = "<static_key_ID>"
      secret_key = "<secret_key>"
      bucket     = "<bucket_name>"
      acl        = "public-read"
    
      website {
        index_document = "<absolute_path_to_website_home_page_file>"
        error_document = "<absolute_path_to_error_file>"
        routing_rules  = <<EOF
        [
          {
            "Condition": {
              "KeyPrefixEquals": "<object_key_prefix>",
              "HttpErrorCodeReturnedEquals": "<HTTP_response_code>"
            },
            "Redirect": {
              "Protocol": "<new_schema>",
              "HostName": "<new_domain_name>",
              "ReplaceKeyPrefixWith": "<new_object_key_prefix>",
              "ReplaceKeyWith": "<new_object_key>",
              "HttpRedirectCode": "<new_HTTP_response_code>"
            }
          },
        ...
        ]
        EOF
      }
    }
    ...
    

    Where:

    • access_key: Static access key ID.

      Note

      In addition to static access keys, you can use an IAM token for authentication in Object Storage. For more details, see Creating a bucket and the relevant provider documentation.

    • secret_key: Secret access key value.

    • bucket: Bucket name.

    • acl: ACL access management parameters.

    • website: Website parameters:

      • index_document: Absolute path to the website home page file. This is a required parameter.
      • error_document: Absolute path to the file the user will see in case of 4xx errors. This is an optional parameter.
      • routing_rules: Rules for redirecting requests in JSON format. Each rule's Condition and Redirect fields must contain at least one key-value pair. For more information about the supported fields, see the data schema of the relevant API method (the For conditionally redirecting requests tab).

    For more information about the yandex_storage_bucket resource parameters in Terraform, see this TF provider article.

  2. Check the configuration using this command:

    terraform validate
    

    If the configuration is correct, you will get this message:

    Success! The configuration is valid.
    
  3. Run this command:

    terraform plan
    

    The terminal will display a list of resources with their parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.

  4. Apply the configuration changes:

    terraform apply
    
  5. Confirm the changes: type yes into the terminal and press Enter.

    You can use the management console to check the settings for conditionally redirecting requests.

To set up conditional redirects for bucket requests, use the update REST API method for the Bucket resource, the BucketService/Update gRPC API call, or the upload S3 API method.

Request redirects from HTTP to HTTPS are enabled automatically once you set up HTTPS access to a bucket. No other settings are required.

See alsoSee also

  • Custom domain
  • Multiple domain name support for a website
  • Configuring HTTPS

Was the article helpful?

Previous
Managing object custom metadata
Next
Support for your own domain
Yandex project
© 2025 Yandex.Cloud LLC