A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.google.com/storage/docs/hosting-static-website-http below:

Hosting a static website using HTTP | Cloud Storage

Skip to main content Hosting a static website using HTTP

Stay organized with collections Save and categorize content based on your preferences.

This tutorial describes how to configure a Cloud Storage bucket to host a static website for a domain you own. Static web pages can contain client-side technologies such as HTML, CSS, and JavaScript. They cannot contain dynamic content such as server-side scripts like PHP.

This tutorial shows you how to serve content over HTTP. For a tutorial that uses HTTPS, see Hosting a static website.

For examples and tips on static web pages, including how to host static assets for a dynamic website, see the Static Website page.

Caution: This tutorial makes content available to the public internet. We recommend that you don't serve content that contains sensitive or private data from your Cloud Storage bucket. Objectives In this tutorial you will: Costs

This tutorial uses the following billable component of Google Cloud:

See the Monitoring your storage charges tip for details on what charges may be incurred when hosting a static website, and see the Pricing page for details on Cloud Storage costs.

Before you begin
  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.

    Go to project selector

  5. Verify that billing is enabled for your Google Cloud project.

  6. Have a domain that you own or manage. If you don't have an existing domain, there are many services through which you can register a new domain, such as Cloud Domains.

    This tutorial uses the domain example.com.

  7. Verify that you own or manage the domain that you will be using. Make sure you are verifying the top-level domain, such as example.com, and not a subdomain, such as www.example.com.

    Note: If you own the domain you are associating to a bucket, you might have already performed this step in the past. If you purchased your domain through Cloud Domains, verification is automatic.

Connecting your domain to Cloud Storage

To connect your domain to Cloud Storage, create a CNAME record through your domain registration service. A CNAME record is a type of DNS record. It directs traffic that requests a URL from your domain to the resources you want to serve, in this case objects in your Cloud Storage buckets. For www.example.com, the CNAME record might contain the following information:

NAME                  TYPE     DATA
www                   CNAME    c.storage.googleapis.com.

For more information about CNAME redirects, see URI for CNAME aliasing.

To connect your domain to Cloud Storage:

  1. Create a CNAME record that points to c.storage.googleapis.com..

    Your domain registration service should have a way for you to administer your domain, including adding a CNAME record. For example, if you use Cloud DNS, instructions for adding resource records can be found on the Add, modify, and delete records page.

    Note: DNS does not support creating a CNAME record on a root domain, such as example.com, so in most cases, you must create your CNAME record on a subdomain, such as www.example.com or myblog.example.com. Some DNS providers offer a non-standard feature that allows a root domain to be aliased to another name without the use of CNAME. Consult your DNS provider documentation to determine if such a feature is available.
Creating a bucket

Create a bucket whose name matches the CNAME you created for your domain.

For example, if you added a CNAME record pointing from the www subdomain of example.com to c.storage.googleapis.com., then the Google Cloud CLI command to create a bucket with the name www.example.com would look similar to the following:

gcloud storage buckets create gs://www.example.com --location=US

For complete instructions to creating buckets with different tools, see Create buckets.

Uploading your site's files

To add to your bucket the files you want your website to serve:

Console
  1. In the Google Cloud console, go to the Cloud Storage Buckets page.

    Go to Buckets

  2. In the list of buckets, click the name of the bucket that you created.

  3. Click the Upload files button in the Objects tab.

  4. In the file dialog, browse to the desired file and select it.

After the upload completes, you should see the file name along with file information displayed in the bucket.

Command line

Use the gcloud storage cp command to copy files to your bucket. For example, to copy the file index.html from its current location Desktop:

gcloud storage cp Desktop/index.html gs://www.example.com

If successful, the response looks like the following example:

Completed files 1/1 | 164.3kiB/164.3kiB
Client libraries C++

For more information, see the Cloud Storage C++ API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

C#

For more information, see the Cloud Storage C# API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

Go

For more information, see the Cloud Storage Go API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

Java

For more information, see the Cloud Storage Java API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

The following sample uploads an individual object:

The following sample uploads multiple objects concurrently:

The following sample uploads all objects with a common prefix concurrently:

Node.js

For more information, see the Cloud Storage Node.js API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

The following sample uploads an individual object:

The following sample uploads multiple objects concurrently:

The following sample uploads all objects with a common prefix concurrently:

PHP

For more information, see the Cloud Storage PHP API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

Python

For more information, see the Cloud Storage Python API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

The following sample uploads an individual object:

The following sample uploads multiple objects concurrently:

The following sample uploads all objects with a common prefix concurrently:

Ruby

For more information, see the Cloud Storage Ruby API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

REST APIs Sharing your files

To make all objects in a bucket readable to everyone on the public internet:

Caution: Before making your bucket publicly accessible, make sure that the files in your bucket do not contain sensitive or private information. Console
  1. In the Google Cloud console, go to the Cloud Storage Buckets page.

    Go to Buckets

  2. In the list of buckets, click the name of the bucket that you want to make public.

  3. Select the Permissions tab near the top of the page.

  4. If the Public access pane reads Not public, click the button labeled Remove public access prevention, and click Confirm in the dialog that appears.

  5. Click the add_box Grant access button.

    The Add principals dialog box appears.

  6. In the New principals field, enter allUsers.

  7. In the Select a role drop down, select the Cloud Storage sub-menu, and click the Storage Object Viewer option.

  8. Click Save.

  9. Click Allow public access.

Once shared publicly, a link icon appears for each object in the public access column. You can click this icon to get the URL for the object.

Command line

Use the buckets add-iam-policy-binding command:

gcloud storage buckets add-iam-policy-binding gs://www.example.com --member=allUsers --role=roles/storage.objectViewer
Client libraries C++

For more information, see the Cloud Storage C++ API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

C#

For more information, see the Cloud Storage C# API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

Go

For more information, see the Cloud Storage Go API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

Java

For more information, see the Cloud Storage Java API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

Node.js

For more information, see the Cloud Storage Node.js API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

PHP

For more information, see the Cloud Storage PHP API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

Python

For more information, see the Cloud Storage Python API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

Ruby

For more information, see the Cloud Storage Ruby API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

REST APIs Note: roles/storage.objectViewer includes permission to list the objects in the bucket.

If wanted, you can alternatively make portions of your bucket publicly accessible.

Visitors receive a http 403 response code when requesting the URL for a non-public or non-existent file. See the next section for information on how to add an error page that uses a http 404 response code.

Recommended: Assigning specialty pages

You can assign an index page suffix, which is controlled by the MainPageSuffix property and a custom error page, which is controlled by the NotFoundPage property. Assigning either is optional, but without an index page, nothing is served when users access your top-level site, for example, http://www.example.com. For more information, see Website configuration examples.

In the following sample, the MainPageSuffix is set to index.html and NotFoundPage is set to 404.html:

Console
  1. In the Google Cloud console, go to the Cloud Storage Buckets page.

    Go to Buckets

  2. In the list of buckets, find the bucket you created.

  3. Click the Bucket overflow menu (more_vert) associated with the bucket and select Edit website configuration.

  4. In the website configuration dialog, specify the main page and error page.

  5. Click Save.

Note: View, change, or remove these settings from the Edit website configuration menu. Command line

Use the buckets update command with the --web-main-page-suffix and --web-error-page flags:

gcloud storage buckets update gs://www.example.com --web-main-page-suffix=index.html --web-error-page=404.html

If successful, the command returns:

Updating gs://www.example.com/...
  Completed 1
Note: Change or remove these settings with additional buckets update commands and view these settings with the buckets describe command. Client libraries C++

For more information, see the Cloud Storage C++ API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

C#

For more information, see the Cloud Storage C# API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

Go

For more information, see the Cloud Storage Go API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

Java

For more information, see the Cloud Storage Java API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

Node.js

For more information, see the Cloud Storage Node.js API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

PHP

For more information, see the Cloud Storage PHP API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

Python

For more information, see the Cloud Storage Python API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

Ruby

For more information, see the Cloud Storage Ruby API reference documentation.

To authenticate to Cloud Storage, set up Application Default Credentials. For more information, see Set up authentication for client libraries.

REST APIs Testing the website Note: Depending on your domain registration service, it may take hours or longer for your CNAME record to begin routing requests to your Cloud Storage bucket.

Verify that content is served from the bucket by requesting the domain name in a browser. You can do this with a path to an object or with just the domain name, if you set the MainPageSuffix property.

For example, if you have an object named test.html stored in a bucket named www.example.com, check that it's accessible by going to www.example.com/test.html in your browser.

Clean up

After you finish the tutorial, you can clean up the resources that you created so that they stop using quota and incurring charges. The following sections describe how to delete or turn off these resources.

Deleting the project

The easiest way to eliminate billing is to delete the project that you created for the tutorial.

To delete the project:

    Caution: Deleting a project has the following effects:

    If you plan to explore multiple architectures, tutorials, or quickstarts, reusing projects can help you avoid exceeding project quota limits.

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.
Note: If you do not want to delete the entire project, you can alternatively delete the bucket that you used for hosting your website. What's next

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-07 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4