Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
© 2022 Yandex.Cloud LLC
Yandex Object Storage
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Buckets
      • Creating a bucket
      • Deleting a bucket
      • Limiting the maximum size of a bucket
      • Allowing public access to a bucket
      • Bucket encryption
      • Managing object lifecycles
      • Managing CORS configurations
      • Managing bucket policies
      • Managing bucket versioning
      • Editing a bucket ACL
      • Enabling logging
    • Objects
      • Uploading an object
      • Getting information about an object
      • Downloading an object
      • Getting a public link to an object
      • Deleting an object
      • Deleting all objects
      • Deleting a partially uploaded object
      • Editing an object ACL
    • Static website hosting
      • Hosting setup
      • Support for your own domain
      • Support for multiple domain names
      • Configuring HTTPS
    • Access management
      • Applying an access policy
  • Practical guidelines
    • Getting object query statistics with S3 Select
    • Getting website traffic statistics with S3 Select
    • Generating a billing report with resource break-down using S3 Select
    • Server-side encryption
    • Integrating an L7 load balancer with the CDN and Object Storage
    • Blue-green and canary deployment
    • Analyzing logs in DataLens
    • Using initialization actions to configure GeeseFS in Yandex Data Proc
  • Concepts
    • Overview
    • Bucket
    • Objects
    • Bucket versioning
    • Object lifecycles
    • CORS
    • Static website hosting
    • Pre-signed URLs
    • Multipart upload
    • Access control lists (ACLs)
    • Bucket Policy
    • Uploading files via an HTML form
    • Storage class
    • Logging actions with a bucket
    • Backups
    • TLS protocol
    • S3 Select query language
    • Quotas and limits
  • Tools
    • All tools
    • Console clients
      • AWS CLI
      • S3cmd
    • File browsers
      • CyberDuck
      • WinSCP
    • SDK
      • AWS SDK for Java
      • Python SDK (boto)
      • The AWS SDK for .NET
      • AWS SDK for C++
      • AWS SDK for PHP
      • AWS SDK for Go
    • FUSE
      • GeeseFS
      • s3fs
      • goofys
    • FTP
      • Docker container for (S)FTP(S)
  • API reference
    • REST (Amazon S3-compatible)
      • How to use the API
      • Signing requests
      • API reference
        • All services and methods
        • Bucket
          • All methods
          • create
          • getBucketEncryption
          • getMeta
          • listObjects
          • listBuckets
          • deleteBucket
          • deleteBucketEncryption
          • putBucketEncryption
          • putBucketVersioning
          • getBucketVersioning
          • putBucketLogging
          • getBucketLogging
          • listObjectVersions
        • Object
          • All methods
          • upload
          • get
          • copy
          • getObjectMeta
          • delete
          • deleteMultipleObjects
          • options
          • selectObjectContent
        • Multipart upload
          • General multipart upload procedure
          • startUpload
          • uploadPart
          • copyPart
          • listParts
          • abortUpload
          • completeUpload
          • listUploads
        • Static Website Hosting
          • All methods
          • upload
          • get
          • delete
          • Static website response codes
        • CORS
          • All methods
          • XML structure of CORS configuration
          • upload
          • get
          • delete
        • Lifecycles
          • All methods
          • XML structure of lifecycle configuration
          • upload
          • get
          • delete
        • ACL
          • All methods
          • XML structure of ACL configuration
          • objectGetAcl
          • objectPutAcl
          • bucketGetAcl
          • bucketPutAcl
        • Bucket Policy
          • All methods
          • GetBucketPolicy
          • PutBucketPolicy
          • DeleteBucketPolicy
          • Data schema
          • Actions
          • Conditions
        • Common request headers
        • Common response headers
        • Responses
    • gRPC and REST
      • Authentication in the API
      • gRPC
        • Overview
        • BucketService
        • OperationService
      • REST
        • Overview
        • Bucket
          • Overview
          • create
          • delete
          • deleteHTTPSConfig
          • get
          • getHTTPSConfig
          • getStats
          • list
          • setHTTPSConfig
          • update
  • Access management
  • Pricing policy
    • Current pricing policy
    • Archive
      • Before January 1, 2019
      • From January 1 to March 1, 2019
  • Questions and answers
  1. Step-by-step instructions
  2. Static website hosting
  3. Hosting setup

Hosting setup

Written by
Yandex Cloud
  • Static website hosting
  • Redirect all requests
  • Conditional request redirection

Object Storage lets you configure a bucket:

  • For static website hosting.
  • To redirect all requests.
  • For conditionally redirecting requests.

Static website hosting

Management console
Terraform
  1. In the management console, go to the bucket you want to configure hosting for.
  2. Make sure public access is allowed to the bucket. If not, follow the instructions in Enabling public access for bucket operations.
  3. In the left panel, select Website.
  4. Under Hosting, specify:
    • The website homepage.
    • The page to be displayed to the user in the event of 4xx errors. Optional.
  5. Click Save.

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

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

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

    provider "yandex" {
      token     = "<OAuth>"
      cloud_id  = "<cloud ID>"
      folder_id = "<folder ID>"
      zone      = "ru-central1-a"
    }
    
    resource "yandex_storage_bucket" "test" {
      access_key = "<static key ID>"
      secret_key = "<secret key>"
      bucket = "<bucket name>"
      acl    = "public-read"
    
      website {
        index_document = "index.html"
        error_document = "error.html"
      }
    
    }
    

    Where:

    • access_key: The ID of the static access key.

    • secret_key: The value of the secret access key.

    • bucket: Bucket name.

    • acl: Parameters for ACL.

    • website: Website parameters:

      • index_document: Absolute path to the file of the website's homepage. Required parameter.
      • error_document: Absolute path to the file to be displayed to the user in the event of 4xx errors. Optional.
  2. Make sure that the configuration files are correct.

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

    2. Run the check using the command:

      terraform plan
      

    If the configuration is described correctly, the terminal displays a list of created resources and their parameters. If there are errors in the configuration, Terraform points them out.

  3. Deploy the cloud resources.

    1. If the configuration doesn't contain any errors, run the command:
    terraform apply
    
    1. Confirm that you want to create the resources.

    Afterwards, all the necessary resources are created in the specified folder. You can check that the resources are there with the correct settings using the management console.

Redirect all requests

Management console
  1. In the management console, go to the bucket you wish to configure redirection for.
  2. Make sure public access is allowed to the bucket. If not, follow the instructions in Enabling public access for bucket operations.
  3. In the left panel, select Website.
  4. Under Redirect, specify:
    • The domain name of the host to act as the redirect target for all requests to the current bucket.
    • The protocol if the specified host accepts requests strictly over a specific protocol.

Conditional request redirection

Management console
  1. In the management console, go to the bucket you wish to configure conditional request redirects for.
  2. Make sure public access is allowed to the bucket. If not, follow the instructions in Enabling public access for bucket operations.
  3. In the left panel, select Website.
  4. Under Hosting, add a redirect rule with the redirect condition and the new address.
    • Condition. For example, you can do a redirect when you receive a specified response code or if the beginning of the object key in a request matches the specified key.
    • Redirection:
      • The domain name of the host where requests that satisfy the condition should redirect.
      • The protocol to use to send redirected requests.
      • Response code to determine the redirect type.
      • Replace the entire key specified in the condition or its initial sequence only.

Was the article helpful?

Language / Region
© 2022 Yandex.Cloud LLC
In this article:
  • Static website hosting
  • Redirect all requests
  • Conditional request redirection