> ## Documentation Index
> Fetch the complete documentation index at: https://developer.upsun.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Serve static sites

> Serve completely static sites

Static site generators are a popular way to create fast sites.
Because there's no need to wait for responses from servers, the sites may load faster.

To learn how to serve your static site using Upsun Cloud,
you can start with the required [minimal app configuration](#minimal-app-configuration) and build on it,
or jump straight to an [example of a complete configuration](#complete-example-configuration).

## Minimal app configuration

To successfully serve a static site using Upsun Cloud,
you need to set up a minimal app configuration similar to the following:


&#x20;   applications:
&#x20;     myapp:
&#x20;       \# The type of the application to build.
&#x20;       type: "nodejs:\{\{version:nodejs:latest}}"
&#x20;       source:
&#x20;         root: "/"
&#x20;       \# The web key configures the web server running in front of your app.
&#x20;       web:
&#x20;         locations:
&#x20;           /:
&#x20;             \# Static site generators usually output built static files to a specific directory.
&#x20;             \# Define this directory (must be an actual directory inside the root directory of your app)
&#x20;             \# as the root for your static site.
&#x20;             root: "public"
&#x20;             \# Files to consider when serving a request for a directory.
&#x20;             index:
&#x20;               \- index.html

See more information on the required minimal settings:

* [Top-level properties](https://developer.upsun.com/docs/configure-apps/app-reference/single-runtime-image.md#primary-application-properties).
* [`web` property](https://developer.upsun.com/docs/configure-apps/image-properties/web).
* [`locations` properties](https://developer.upsun.com/docs/configure-apps/image-properties/web#locations).

## Add more features

### Allow static files but not dynamic files on PHP containers

If you have a PHP container,
you might want to enable client-side scripts but disable server-side scripts.

To enable static files that don't match any rule while disabling server-side scripts on a PHP container,
use the following configuration:


&#x20;   applications:
&#x20;     myapp:
&#x20;       \# The type of the application to build.
&#x20;       type: "nodejs:\{\{version:nodejs:latest}}"
&#x20;       source:
&#x20;         root: "/"
&#x20;       web:
&#x20;         locations:
&#x20;           '/':
&#x20;             ...
&#x20;             scripts: false
&#x20;             allow: true

See more information on [`locations` properties](https://developer.upsun.com/docs/configure-apps/image-properties/web#locations).

### Create cache rules

You can create sensible cache rules to improve performance.
For example, if you publish new content regularly without updating images or site files much,
you might want to cache text files for a day but all image files for longer.

To do so, use a configuration similar to the following:


&#x20;   applications:
&#x20;     myapp:
&#x20;       \# The type of the application to build.
&#x20;       type: "nodejs:\{\{version:nodejs:latest}}"
&#x20;       source:
&#x20;         root: "/"
&#x20;       web:
&#x20;         locations:
&#x20;           '/':
&#x20;             ...
&#x20;             expires: 24h
&#x20;             rules:
&#x20;               \\.(css|js|gif|jpe?g|png|svg)\$:
&#x20;                 expires: 4w

You can also set a `Cache-Control` header in your rules.


&#x20;   applications:
&#x20;     \<APP\_NAME>:
&#x20;       web:
&#x20;         locations:
&#x20;           '/':
&#x20;             ...
&#x20;             expires: 24h
&#x20;             rules:
&#x20;               .(css|js|gif|jpe?g|png|svg)\$:
&#x20;               headers:
&#x20;                 Cache-Control: "public, max-age=2419200, immutable"
&#x20;&#x20;

If `expires` and a `Cache-Control` header are set, the rule ignores the `expires` and sets only the `Cache-Control` header. For this reason, make sure
to add a `max-age` value, in seconds, for the `Cache-Control` header.

### Conserve the server

Because your site is completely static, it doesn't need the server to be running.
To set a background process that blocks the server and conserves resources,
use the following configuration:


&#x20;   applications:
&#x20;     \<APP\_NAME>:
&#x20;       \# The type of the application to build.
&#x20;       type: "nodejs:\{\{version:nodejs:latest}}"
&#x20;       source:
&#x20;         root: "/"
&#x20;       web:
&#x20;         commands:
&#x20;           start: sleep infinity

You can also use this place to start small programs,
such as a [script to handle 404 errors](https://support.platform.sh/hc/en-us/community/posts/16439636723474).

## Complete example configuration


&#x20;   applications:
&#x20;     \<APP\_NAME>:
&#x20;       \# The type of the application to build.
&#x20;       type: "python:\{\{version:python:latest}}"
&#x20;       source:
&#x20;         root: "/"
&#x20;       web:
&#x20;         locations:
&#x20;           '/':
&#x20;             \# The public directory of the application relative to its root
&#x20;             root: 'public'
&#x20;             \# The files to look for when serving a directory
&#x20;             index:
&#x20;               \- 'index.html'
&#x20;             \# Disable server-side scripts
&#x20;             scripts: false
&#x20;             allow: true
&#x20;             \# Set caching policy
&#x20;             expires: 24h
&#x20;             rules:
&#x20;               \\.(css|js|gif|jpe?g|png|svg)\$:
&#x20;                 expires: 4w

&#x20;         commands:
&#x20;           \# Run a no-op process that uses no CPU resources since this is a static site
&#x20;           start: sleep infinity


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.