Skip to main content

Host a static website

In an S3 public bucket, you can:

  • host a static website for fast access to files and reduced storage costs;
  • configure an error page. If a user requests a non-existent object, the request will be processed according to the settings: another object will be returned or a redirect to an external URL will occur.

Host a static website

Static websites consist of a set of files (HTML, JS, graphics, fonts) that can be stored as objects in a bucket. The website will open at the address of the bucket's public domain or custom domain, if added to the bucket.

There are two ways to host a website:

  • hosting — you specify the main page of the website, which is stored as an object in a public bucket;
  • web listing — instead of displaying the main page, you enable returning a list of objects in the bucket and set your own CSS styles.

Configure hosting

  1. In the bucket, upload an object — an HTML file that will be the main page.
  2. In the Control panel, in the top menu, click Products and select S3.
  3. Go to the Buckets section.
  4. Open the bucket page → Website tab.
  5. In the Website block, turn on the toggle switch.
  6. Open the Hosting tab.
  7. Enter the path to the object with the main page with the extension .html.
  8. Click Save.

Configure web listing

  1. If you want to store a file with CSS styles in the bucket, upload it.

  2. In the Control panel, in the top menu, click Products and select S3.

  3. Go to the Buckets section.

  4. Open the bucket page → Website tab.

  5. In the Website block, turn on the toggle switch.

  6. Open the Web listing tab.

  7. Enter the path to the CSS file. The format of the path depends on where the file is stored:

    • in the bucket — enter the path to the object with CSS styles;
    • on a third-party resource — enter the URL of the CSS file.
  8. Click Save.

Configure an error page

If users access a non-existent object, an error will occur, which can be handled in two ways:

Return an object from the bucket

  1. In the Control panel, in the top menu, click Products and select S3.
  2. Go to the Buckets section.
  3. Open the bucket page → Website tab.
  4. In the Error page block, turn on the toggle switch.
  5. Optional: if you want the object to be returned with a 200 code, select it as the response code. By default, the request will return a 400 code.
  6. In the Resource field, enter the path to the object with the error page with the extension .html.
  7. Click Save.

Redirect the request

  1. In the Control panel, in the top menu, click Products and select S3.
  2. Go to the Buckets section.
  3. Open the bucket page → Website tab.
  4. In the Error page block, turn on the toggle switch.
  5. Select the 307 response code.
  6. In the Resource field, enter a valid external URL to which the redirection will be performed if the requested object is missing.
  7. Click Save.

Object paths

When hosting a static website or configuring an error page, you will need to enter the path to the object in the bucket — absolute or relative.

Absolute path

An absolute path always starts with the / character and is specified in the format /<prefix>/<object_name>, where:

  • <prefix> — prefix (path to the object) — if any;
  • <object_name> — object name with extension.

If an absolute path is specified, when an object is requested, the storage logic will always look for it relative to the bucket root — at <uuid>.selstorage.ru/<bucket_name>. If there is a prefix in the request after the bucket name, it will be ignored.

If an incorrect path is specified, the object will not be returned.

note

For example, if the full address of the object is <uuid>.selstorage.ru/bucket/prefix/file.html, you specified /prefix/file.html as the path, and the request is made to <uuid>.selstorage.ru/bucket/prefix/, the object will be returned.

Relative path

A relative path never starts with the / character and is specified in the format <prefix>/<object_name> or <object_name>, where:

  • <prefix>/ — optional: prefix (path to the object);
  • <object_name> — object name with extension.

If a relative path is specified, the storage logic will search for the requested object while considering the prefix specified in the bucket request.

note

For example, if the full address of the object is <uuid>.selstorage.ru/bucket/prefix/file.html, you specified file.html as the path, and the request is made to <uuid>.selstorage.ru/bucket/prefix/, the object will be returned.

note

For example, if the full address of the object is <uuid>.selstorage.ru/bucket/prefix/file.html, you specified prefix/file.html as the path, and the request is made to <uuid>.selstorage.ru/bucket/prefix/, the object will not be returned because the storage logic will look for the object at the non-existent address <uuid>.selstorage.ru/bucket/prefix/prefix/file.html.