Skip to content

Configure a static website

Object store may be a cheap and convenient solution to host a static website.

There is lot of static website generators, like Hugo or Jekyll.

Set public read access to your container

First, set the read ACLs on your container, to create a public access to your files.

openstack container create website
swift post -r '.r:*,.rlistings' website

Warning

All files in your container will become public readable.

Upload your website

swift upload website index.html
swift upload website style.css script.js

Define the reference web page (index file)

For this example, first page is index.html

swift post -m 'web-index:index.html' website

Now you should be able to see your website with default url: https://pub1-api.cloud.infomaniak.ch/object/v1/AUTH_d7a1d.../website/

Directory listing

To enable directory listing, you won't need to setup the reference web page but you will need to modify your read ACL and to add :

swift post -r '.r:*,.rlistings' website
swift post -m 'web-listings: true' website

You can of course use index file and directory listing on a single container.

Customisations

You can customize the listing style sheet, with another meta parameter referencing your CSS file:

swift post -m 'web-listings-css:listings.css' website

And even allow custom error files:

swift post -m 'web-error:error.html' website

Then, HTTP 401 should load 401error.html, HTTP 404 should load 404error.html, etc.

Last thing if you uploaded 0-byte objects (like directories):

swift post -m 'web-directory-type:text/directory' website

Now 0-byte objects with a content-type of text/directory will be treated as directories rather than objects.

Check your setup

You can verify ACLs and meta set on your container with command:

swift stat --lh website
                Account: AUTH_d7a1d09c0323488aa00d9e163f3655bf
              Container: website
                Objects: 1
                  Bytes: 116
               Read ACL: .r:*,.rlistings
              Write ACL:
      Meta Web-Listings: true
         Meta Web-Index: index.html
Meta Web-Listings-Label: /object

API url specific case

You can access your files through API url such as https://s3.pub1. infomaniak.cloud/object/v1/AUTH_d7a1d09.../website/, but by default it won't work because Swift will look for /v1/AUTH_d7a1d09.../website/index.html file. In our case, we have a leading
/object/ to our index file.

We can add a specific meta to add this /object/ path in url using the CLI:

swift post -m 'web-listings-label:/object/' website

Access (urls) for your content

You can access your content through url https://s3.pub1.infomaniak.cloud/object/v1/AUTH_d7a1d09.../website/, but this is not so fancy...

Swift supports some convenient shortcuts, with project id and container. You can then use:

  • https://<projectid>.s3.pub1.infomaniak.cloud/<container>) (eg. https://d7a1d09c0323488aa00d9e163f3655bf.s3.pub1.infomaniak.cloud/website/)
  • https://<container>.<projectid\.s3.pub1.infomaniak.cloud (eg. https://website.d7a1d09c0323488aa00d9e163f3655bf.s3.pub1.infomaniak.cloud/)

Warning

SSL certificate can be invalid for these URLs.

Using your own domain

Swift supports also a middleware to redirect a domain or subdomain to your static website.

To enable that, you will need to configure a CNAME record and point it to the Swift full url (<container>.<projectid>.s3.pub1.infomaniak.cloud).

host test1.mydomain.net
test1.mydomain.net is an alias for website.d7a1d09c0323488aa00d9e163f3655bf.s3.pub1.infomaniak.cloud.
Then test your new URL :
curl -k https://test1.mydomain.net
<html>
...
</html>

Warning

SSL certificates may not be valid for your domain / subdomain.

Success

You have deployed a static website using Infomaniak Object Storage !