Static site hosting
Static site hosting — an additional option for a bucket in VK Object Storage that extends the capabilities of access to static content. Without this option, the content of an object is retrieved via a URL corresponding to its key. Static site hosting allows combining static content with redirection rules, as well as specifying an index page (for example, index.html) and an error page returned on request errors (for example, 404).
Usage examples:
- a business card website,
- a personal blog,
- landing pages,
- request redirection,
- documentation.
A static website based on VK Object Storage may consist of:
- static content: HTML, CSS, media files (images, audio, video), documents (PDF, TXT) and other formats viewable in a browser.
- JavaScript script files that do not require server-side processing: expandable menus, tabs, accordions, etc.
After the configuration is installed, the static website is available at:
https://<BUCKET_NAME>.hb-website.<ENDPOINT_HOSTNAME>/<PREFIX>
Here:
-
<BUCKET_NAME>— the name of the bucket for which the static website configuration was installed; -
<ENDPOINT_HOSTNAME>— the host name of the VK Object Storage service, must match the region of the account:hb.vkcloud-storage.ruorhb.ru-msk.vkcloud-storage.ru— the domain of the Moscow region;hb.kz-ast.vkcloud-storage.ru— the domain of the Kazakhstan region.
-
<PREFIX>— the key prefix of the index page object. Can be empty.
The configuration is provided in JSON format and is used when managing the configuration via AWS CLI.
General structure of the configuration:
{"IndexDocument": { // Index page"Suffix": "string"},"ErrorDocument": { // Error page"Key": "string"},"RoutingRules": [ // Redirection rules{"Condition": {"HttpErrorCodeReturnedEquals": "string","KeyPrefixEquals": "string"},"Redirect": {"HostName": "string","HttpRedirectCode": "string","Protocol": "http"|"https","ReplaceKeyPrefixWith": "string","ReplaceKeyWith": "string"}}...],"RedirectAllRequestsTo": { // Unconditional redirection of all requests"HostName": "string","Protocol": "http"|"https"}}
IndexDocument — a configuration element that specifies the index page.
Compatibility of IndexDocument with other configuration elements:
Configuration element | Compatibility | Functionality |
|---|---|---|
| ||
| ||
|
IndexDocument parameters:
Name | Description |
|---|---|
| |
| The suffix (name) for the index page object. Format: When the website page is opened, the content of the object with the specified value will be loaded. Cannot contain the Full path: |
ErrorDocument — a configuration element that specifies the error page. It is used together with the IndexDocument configuration element, which specifies the index page.
For example, when opening a non-existent page, a 404 error will occur. Instead of the non-existent page, the content of the specified object, for example errordoc/file.html, will be loaded.
Compatibility of ErrorDocument with other configuration elements:
Configuration element | Compatibility | Functionality |
|---|---|---|
| ||
| ||
|
ErrorDocument parameters:
Name | Description |
|---|---|
| |
| The full key of the error page object. Format: For an HTTP response Full path: |
RoutingRules — a configuration element that specifies redirection rules. It is used together with the IndexDocument configuration element, which specifies the index page.
Compatibility of RoutingRules with other configuration elements:
Configuration element | Compatibility | Functionality |
|---|---|---|
| ||
| ||
|
RoutingRules parameters:
Name | Description |
|---|---|
| |
| The conditions for the rule to trigger, in the If no condition is specified, the redirection will trigger for all requests. Full path: |
| The error code in the If used together with Format: Upon receiving an HTTP response with the specified error code, the rule specified in Full path: |
| The key prefix of the requested object. If a full key is specified, the rule will apply only to that object. If used together with Format: When opening a page with the specified key or prefix, the rule specified in Full path: |
| Specifies the redirection settings in the Full path: |
| The name of the host to which the redirection will be performed. Format: Can be used together with other If the value is not specified, the host name will not be changed. Full path: |
| The HTTP code in the Format: If the value is not specified, the default response code Can be used together with other Full path: |
| Specified when the protocol needs to be changed. Format: Possible values: Can be used together with other Full path: |
| The object key prefix to replace the prefix of the requested object with. Format: If an empty string is specified, the new request will have no prefix. Usually used together with Can be used together with the Incompatible with the Full path: |
| The key of the object to redirect to. Format: Can be used together with the Incompatible with the Full path: |
RedirectAllRequestsTo — a configuration element that specifies unconditional redirection rules for all website requests.
Compatibility of RedirectAllRequestsTo with other configuration elements:
Configuration element | Compatibility | Functionality |
|---|---|---|
| ||
| ||
|
RedirectAllRequestsTo parameters:
Name | Description |
|---|---|
| |
| The name of the host to which the redirection will be performed. Required parameter. Format: Can be used together with Full path: |
| Specified when the protocol needs to be changed. Format: Possible values: Can be used together with Full path: |
Some parameters are incompatible with each other, so the number of their combinations is limited.
-
Only the index page
IndexDocument:{"IndexDocument": {"Suffix": "index.html"}} -
The index page
IndexDocumentand the error pageErrorDocument:{"IndexDocument": {"Suffix": "index.html"},"ErrorDocument": {"Key": "error.html"}} -
The index page
IndexDocumentand the redirection rulesRoutingRules:{"IndexDocument": {"Suffix": "index.html"},"RoutingRules": [{"Condition": {"KeyPrefixEquals": "docs/"},"Redirect": {"ReplaceKeyPrefixWith": "documents/","HttpRedirectCode": "301"}}]}In this example, all requests with the
docs/prefix will be redirected todocuments/and return the HTTP response code301. -
The index page
IndexDocument, the error pageErrorDocumentand the redirection rulesRoutingRules:{"IndexDocument": {"Suffix": "index.html"},"ErrorDocument": {"Key": "error.html"},"RoutingRules": [{"Condition": {"HttpErrorCodeReturnedEquals": "404"},"Redirect": {"ReplaceKeyWith": "index.html","HttpRedirectCode": "302"}}]}In this example, upon an HTTP
404error, the request is redirected toindex.html; for other errors, the content oferror.htmlis returned. -
Unconditional redirection
RedirectAllRequestsTofor all requests:{"RedirectAllRequestsTo": {"HostName": "example.com","Protocol": "https"}}In this example, all requests are redirected to
example.comvia thehttpsprotocol. The response always returns the code301.