Hosting setup
Object Storage lets you configure a bucket:
Static website hosting
- In the management console, go to the bucket you want to configure hosting for.
- Make sure public access is allowed to the bucket. If not, follow the instructions in Enabling public access for bucket operations.
- In the left panel, select Website.
- Under Hosting, specify:
- The website homepage.
- The page to be displayed to the user in the event of 4xx errors. Optional.
- 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.
-
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 of4xx
errors. Optional.
-
-
Make sure that the configuration files are correct.
-
In the command line, go to the directory where you created the configuration file.
-
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.
-
-
Deploy the cloud resources.
- If the configuration doesn't contain any errors, run the command:
terraform apply
- 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
- In the management console, go to the bucket you wish to configure redirection for.
- Make sure public access is allowed to the bucket. If not, follow the instructions in Enabling public access for bucket operations.
- In the left panel, select Website.
- 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
- In the management console, go to the bucket you wish to configure conditional request redirects for.
- Make sure public access is allowed to the bucket. If not, follow the instructions in Enabling public access for bucket operations.
- In the left panel, select Website.
- 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.