We removed our free Sandbox April 25th.
You can read more on our blog.

Static

The static service is a simple web server that can be used to host static content (images, packages...) efficiently.

Like all our Nginx-based services, it can receive a custom Nginx configuration snippet, which allows it to be more than a dummy HTTP server.

This makes it ideal to serve:

  • static “maintenance” pages or placeholders for future services,
  • URL routers, to dispatch requests to other services,
  • and of course, static assets that you want to keep on a separate domain, for hardcore optimization reasons (like cookie separation).

Basic Use

Let’s assume that you are building a DotCloud application called “ramen”. For the sake of simplicity, we will also assume that everything related to this application is located in a directory called “ramen-on-dotcloud”.

Let’s setup our environment:

$ dotcloud create ramen
Created application "ramen" using the flavor "sandbox" (Use for development, free and unlimited apps. DO NOT use for production.)
$ mkdir ramen-on-dotcloud

A DotCloud application is described by a Build Files, which is a simple YAML file named “dotcloud.yml” located in our “ramen-on-dotcloud” directory. To add a new service to our app, we just add the following lines to “ramen-on-dotcloud/dotcloud.yml”:

www:
  type: static
  approot: hellostatic

Our static content will be in the “hellostatic” directory:

$ mkdir ramen-on-dotcloud/hellostatic

And we should create a little “index.html” file here:

<html>
<head><title>Hello World!</title></head>
<body>This is a static service running on DotCloud.</body>
</html>

We can now push our application to DotCloud:

$ dotcloud push ramen ramen-on-dotcloud/
# upload /home/.../ramen-on-dotcloud/ ssh://dotcloud@uploader.dotcloud.com:21122/ramen
# rsync
[...]
sent 8.11K bytes  received 352 bytes  995.06 bytes/sec
total size is 14.78K  speedup is 1.75
Deployment for "ramen" triggered. Will be available in a few seconds.
2011-06-28 04:27:34 [api] Waiting for the build. (It may take a few minutes)
2011-06-28 04:27:48 [www.0] service booted
2011-06-28 04:27:48 [www.0] The build started
2011-06-28 04:27:48 [www.0] Fetched code revision rsync-1309235251.44
2011-06-28 04:27:51 [www.0] Reloading nginx configuration: nginx.
2011-06-28 04:27:51 [www.0] The build finished successfully
2011-06-28 04:27:51 [api] Deploy finished

Deployment finished successfully. Your application is available at the following URLs
www: http://ramen-dotcloud.dotcloud.com/

URLs have been generated for each web service in your application from your application an account names. Open your browser to see your new service in action!

If you want to attach a better URL to your application, read the Custom Domains documentation.

Maintenance Page

If you have to take down a service for extended maintenance, you might want to replace it with a maintenance page on a static service for the duration of the maintenance.

To achieve that, put up the files you need for your maintenance page. This could be a single “index.html” page; maybe with some additional assets (images and CSS files); maybe even a whole set of static pages explaining to your users what’s going on.

You will also need create an additional Nginx configuration snippet. Just create the file “ramen-on-dotcloud/hellostatic/nginx.conf” with this content:

location ^~ / {
  try_files $uri $uri/ /index.html ;
}

Note

The ^~ is here to override the default “location /” block shipped with the stock Nginx configuration.

This will instruct Nginx to fall back on the default “index.html” file if the user requests a non-existent page (which will certainly happen if the user is following an external link or bookmark).

After adding the new files and the nginx.conf snippet, run “dotcloud push” again. At the end of the push, go to your service URL, and try to add some extra path at the end: instead of showing a “404 not found” page, you will see the “index.html” page.