Uploading a Website to Google Cloud Platform
Host a Static Website in Google Deject with Cloud Storage
one. Introduction
Every small-business organization owner should accept a domain proper name and website—they are the foundation of your brand and your method to communicate with potential customers.
Your domain name and website are 1 of the primary ways that people find your business, find what products and services you offer, find your contact details, and even transact business with you (e-commerce transactions).
If y'all're only starting your concern at present, then you lot're not expecting very much traffic, so yous want to host a elementary website. You tin practise that in Google Cloud, which makes the process very quick, easy, and inexpensive.
What you'll larn
- How to Create a CNAME record
- How to point that CNAME record to Cloud Storage
- How to create a Cloud Storage bucket named similar your domain
- How to upload and set permissions on the static files for your website
- How to examination your website
Prerequisites
- You demand to exist the possessor/administrator of your domain.
- Y'all need a Google Account.
2. Setup
Google Account and new project
- If you don't already accept a Google Account, then you must create ane. Sign into Deject Console and create a new project.
You can as well edit the Project ID.
- Make sure that billing is enabled for your Google Cloud project. For more information, meet Modify a Project's Billing Settings.
Domain ownership or admin rights
Equally mentioned in the prerequisites, you'll need a domain that you own or manage.
If you don't accept an existing domain, then in that location are many services through which you lot can register a new domain, such as Google Domains.
The following tutorial uses the domain www.cookingincloudhipster.com, which is managed through Google Domains and admin.google.com
- Verify that you own or manage the domain that you lot will utilise. Make sure that you are verifying the meridian-level domain, such every bit cookingincloudhipster.com, and not a subdomain, such as www.cookingincloudhipster.com.
Notation: If you lot ain the domain that you are associating to a bucket, then you might take already performed this step in the past. If you purchased your domain through Google Domains, verification is automated.
- Go to Google Search Console. Enter your domain proper name and press go on.
- If you lot used Google Domains to purchase your domain proper noun, then it will allow for automated ownership verification. However, if you're using another registrar, and then you could have a few more steps.
3. Create a CNAME record
On the web, there are numerous systems that are used to brand sure that you can get where y'all need to go. I of those disquisitional systems is Domain Name Services (DNS), which helps with translating homo-readable names similar www.cookingincloudhipster.com into the numeric IP Accost number of the server that is hosting that website.
Within DNS, there is the ability to add RECORDs to the DNS entry to help other services with being correctly configured. Some of the the common ones are MX or Mail service eXhange RECORDs, which help email systems piece of work.
In this section, yous'll create a CNAME, which is a Canonical Name Record or Alias Record record, so that when someone only enters cookingincloudhipster.com—without the "www"—it volition still lead to the right server.
Follow these steps:
- Become to Google Domains. Click on the "My domains" task. If you need to Sign-in or if yous are a first-time user, then employ your email address to log in. Notice your domain— www.cookingincloudhipster.com.
- Click on "Manage," and so click "DNS."
- DNS Settings screen.
Toward the bottom, expect for the "Custom resources records" panel.
- Add a CNAME tape. A CNAME record is a blazon of DNS record. Information technology directs traffic that requests a URL from your domain to the resources that you want to serve. In this example, those are objects in your Cloud Storage buckets. For more than information, see CNAME redirects.
For www.cookingincloudhipster.com, the CNAME record will contain the following information:
| NAME | TYPE | DATA |
| world wide web.cookingincloudhipster.com | CNAME | c.storage.googleapis.com |
When you're done, it should expect like this:
4. Create a Deject Storage Bucket
Next, you'll create a Cloud Storage bucket to hold your static site files.
Follow these steps:
- Get to the Deject Console. In the left-hand carte du jour, scroll downwardly to the STORAGE category and click on the Storage task.
- Click on Create Saucepan.
- Complete the following fields:
- Name your bucket: Make sure that you name your bucket with your site name, which is www.cookingincloudhipster.com.
- Choose where to store your data: Select Multi-region so that the content is bachelor from more than than 1 cloud region.
- Choose a default storage class for your information: Select Standard. For more information, see Storage classes.
- Choose how to control admission to objects: Fix the bucket permissions for the whole bucket and its contents the same. For information, run across Access control lists (ACLs).
- Click Create.
So far in this codelab, you have been using the Cloud Console graphical user interface. However, you tin can also control Google Cloud with Cloud Crush, which provides you with command-line admission to your cloud resources directly from your browser.
This Debian-based virtual machine is loaded with all the development tools you lot'll demand. It offers a persistent 5GB home directory and runs in Google Deject, profoundly enhancing network functioning and authentication. This means that all you will need for this codelab is a browser (yeah, information technology works on a Chromebook).
- To activate Cloud Shell from the Deject Console, just click Actuate Deject Shell
(it should just take a few moments to provision and connect to the environs).
Once connected to Cloud Shell, you lot should see that y'all are already authenticated and that the project is already set to your PROJECT_ID.
gcloud auth list
Command output
Credentialed accounts: - <myaccount>@<mydomain>.com (active)
gcloud config list project
Command output
[cadre] project = <PROJECT_ID>
If, for some reason, the project is not ready, simply issue the following command:
gcloud config set up project <PROJECT_ID>
Looking for your PROJECT_ID? Cheque out what ID you used in the setup steps or await information technology upwardly in the Cloud Console dashboard:
Deject Shell besides sets some environs variables by default, which may be useful equally you run time to come commands.
echo $GOOGLE_CLOUD_PROJECT
Command output
<PROJECT_ID>
- Finally, set the default zone and project configuration.
gcloud config prepare compute/zone us-central1-f
You can choose a variety of different zones. For more than information, see Regions & Zones.
Here'south the command-line version of "create bucket."
gsutil mb gs://www.cookingincloudhipster.com
v. Upload your website'south files and images
Now, obtain the static files from your website programmer or marketing team. If you're doing information technology yourself, then there are enough of great tutorials on HTML and CSS. Then, upload the static files into the bucket that you created in 1 of iii ways.
Upload files with the Cloud Console
- Go to the Cloud Console. In the left-hand menu, click on the STORAGE category, and so click Storage.
- Click on the bucket name, which is www.cookingincloudhipster.com.
- Nether Bucket details, click Upload folder.
- Upload your website's folders and files.
Upload files past dragging and dropping them
Yous can besides upload files past dragging and dropping them.
Upload files using the gsutil rsync
You lot can also the gsutil rsync command to copy big numbers of files from your local machine to Deject Storage. Yous can apply the -R option to recursively copy directory trees. For case, to synchronize a local directory named local-dir with a bucket, use the following:
gsutil rsync -R local-dir gs://www.cookingincloudhipster.com
six. Set access permissions
You tin either make all files in your saucepan publicly accessible or prepare individual objects to be accessible through your website. Generally, making all files in your bucket accessible is easier and faster.
If you choose to control the accessibility of individual files, and so you lot can set the default object ACL for your bucket and so that subsequent files uploaded to your bucket are shared past default.
Bucket-level access permissions
Employ access permission to the unabridged bucket as a whole. That is safer and, given that information technology is a static website, all of the contents likely need to exist readable for the site to properly load. If you have some design metadata (or hidden files like .DS_Store, which is used on Macintosh, .is a file that stores custom attributes of its containing folder, such as the position of icons or the choice of a groundwork epitome.) They can be individually subconscious or deleted.
- Click Saucepan details, then click Permissions.
- Click Add members.
- Add allUsers with Storage Object Viewer rights.
- Verify that you come across the following:
The files are now visible to the general public. Hooray!
7. Edit website configuration
Now, the last step is to assign an alphabetize folio suffix, which is controlled by the MainPageSuffix property, and a custom fault page, which is controlled by the NotFoundPage property. Assigning either is optional, just without an index page, zero is served when users access your top-level site, in this case— http://www.cookingincloudhipster.com/.
Index pages
An index page (also called a webserver directory alphabetize) is a file served to visitors when they request a URL that doesn't have an associated file. When you assign a MainPageSuffix, Cloud Storage looks for a file with that proper noun and a prefix that matches the URL that the visitor requested.
For instance, say you set the MainPageSuffix of your static website to index.html. Additionally, say y'all have no file named directory in your bucket world wide web.cookingincloudhipster.com. In this state of affairs, if a user requests the URL http://www.cookingincloudhipster.com/directory, Cloud Storage attempts to serve the file www.cookingincloudhipster.com/directory/index.html. If that file also doesn't exist, Cloud Storage returns an error page.
The MainPageSuffix also controls the file served when users request the top-level site. Continuing the above example, if a user requests http://www.cookingincloudhipster.com, Cloud Storage attempts to serve the file www.cookingincloudhipster.com/index.html.
For more data on the cases in which the alphabetize page is served, see Website configuration examples.
Error page
The error folio is the file returned to visitors of your static site who request a URL that does not stand for to an existing file. If y'all take assigned a MainPageSuffix, and so Deject Storage only returns the mistake page if there is neither a file with the requested name nor an applicable index folio.
When returning an fault page, the HTTP response code is 404. The belongings that controls which file acts as the mistake folio is NotFoundPage. If you don't set NotFoundPage, and so users receive a generic fault page.
In the following sample, the MainPageSuffix is ready to index.html and NotFoundPage is set up to 404.html:
gsutil web ready -g index.html -eastward 404-Page.html gs://www.example.com
eight. Test your website
- Now, open up a browser and go to your website— www.cookingincloudhipster.com.
- Confirm that you lot meet the following folio and individual production pages:
Voila! It works and is available via HTTP.
Cleanup
Delete the following Google Cloud resource:
- The Cloud Storage bucket
- The CNAME record
ix. Congratulations!
You created a static website and hosted it in Google Cloud!
Except equally otherwise noted, the content of this page is licensed nether the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, run across the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
fraleyentioncesay1992.blogspot.com
Source: https://codelabs.developers.google.com/codelabs/cloud-webapp-hosting-gcs
0 Response to "Uploading a Website to Google Cloud Platform"
Post a Comment