Goal
To serve a static HTML page on Platform.sh.
Assumptions
You will need:
- An empty Platform.sh project
- SSH key configured to the Platform.sh account
Problems
In addition to your HTML file, Platform.sh needs three YAML files to configure an application in a project. These files define the routing, configure the web server, and set minimal defaults for everything else.
Steps
1. Set git remote to Platform.sh project
$ git init
$ platform project:set-remote <project id>
2. Create your HTML file:
./web/index.html
<!DOCTYPE html>
<html>
<body>
<p>Hello World</p>
</body>
</html>
3. Define routes
./.platform/routes.yaml
https://{default}/:
type: upstream
upstream: htmlhowto:http
4. Add empty services
./.platform/services.yaml
# empty
5. Add .platform.app.yaml
./.platform.app.yaml
# The name of this app. Must be unique within a project.
name: htmlhowto
# Any type will work. There is no "plain HTML" type.
type: "python:3.7"
# There is no need for a writable file mount, so set it to the smallest possible size.
disk: 256
# Configure the web server to serve our static site.
web:
commands:
# Run a no-op process that uses no CPU resources, since this is a static site.
start: sleep infinity
locations:
# This tells Nginx to serve from the base directory
"/":
root: "web"
index:
- "index.html"
This is a stripped down application configuration for serving a static file on Platform.sh. You can find more information about additional commands that can be included in .platform.app.yaml
in the Platform.sh documentation.
6. Add, commit, and push these files to your empty Platform.sh project
git add .
git commit -m "Adding configuration to serve a static html file"
git push platform master
7. Test by visiting the URL of your environment.
Conclusion
By adding a route to routes.yaml, and by adding the proper web server configuration to .platform.app.yaml, a project is able to serve static HTML files.