Hosting a static website on Google App Engine

You can use Google App Engine to host a static website. Static web pages can contain client-side technologies such as HTML, CSS, and JavaScript. Hosting your static site on App Engine can cost less than using a traditional hosting provider, as App Engine provides a free tier.

Sites hosted on App Engine are hosted on the subdomain, such as [my-project-id] After you deploy your site, you can map your own domain name to your App Engine-hosted website.

Before you begin

Before you can host your website on Google App Engine:

  1. Create a new Cloud Platform Console project or retrieve the project ID of an existing project to use:

    Go to the Projects page

    Tip: You can retrieve a list of your existing project IDs with gcloud.

  2. Install and then initialize the Google Cloud SDK:

    Download the SDK

Creating a website to host on Google App Engine

Basic structure for the project

This guide uses the following structure for the project:

  • app.yaml: Configure the settings of your App Engine application.
  • www/: Directory to store all of your static files, such as HTML, CSS, images, and JavaScript.
    • css/: Directory to store stylesheets.
      • style.css: Basic stylesheet that formats the look and feel of your site.
    • images/: Optional directory to store images.
    • index.html: An HTML file that displays content for your website.
    • js/: Optional directory to store JavaScript files.
    • Other asset directories.

Creating the app.yaml file

The app.yaml file is a configuration file that tells App Engine how to map URLs to your static files. In the following steps, you will add handlers that will load www/index.html when someone visits your website, and all static files will be stored in and called from the www directory.

Create the app.yaml file in your application's root directory:

  1. Create a directory that has the same name as your project ID. You can find your project ID in the Console.
  2. In directory that you just created, create a file named app.yaml.
  3. Edit the app.yaml file and add the following code to the file:

     runtime: python27
     api_version: 1
     threadsafe: true
     - url: /
       static_files: www/index.html
       upload: www/index.html
     - url: /(.*)
       static_files: www/\1
       upload: www/(.*)

More reference information about the app.yaml file can be found in the app.yaml reference documentation.

Creating the index.html file

Create an HTML file that will be served when someone navigates to the root page of your website. Store this file in your www directory.

    <title>Hello, world!</title>
    <link rel="stylesheet" type="text/css" href="/css/style.css">
    <h1>Hello, world!</h1>
      This is a simple static HTML file that will be served from Google App

Uploading your files to Google App Engine

When you deploy your application files, your website will be uploaded to App Engine. To deploy your app, run the following command from within the root directory of your application where the app.yaml file is located:

gcloud app deploy

Optional flags:

  • Include the --project flag to specify an alternate Cloud Platform Console project ID to what you initialized as the default in the gcloud tool. Example: --project [YOUR_PROJECT_ID]
  • Include the -v flag to specify a version ID, otherwise one is generated for you. Example: -v [YOUR_VERSION_ID]

To learn more about deploying your app from the command line, see Deploying a Python App.

Viewing your application

To launch your browser and view the app at http://[YOUR_PROJECT_ID], run the following command:

gcloud app browse

What’s next

Serve your App Engine-hosted website from a custom domain.

Send feedback about...

App Engine standard environment for Python