What is it meant by Hosting a website?
- Web hosting is a service that provides organizations and individuals with a platform to store their website files and make them accessible online. It allows you to rent space on a server their server space to store your website data, such as HTML and CSS files, media content, and other documents so that your website can be accessed by anyone with an Internet connection.
Who needs this?
- Web hosting allows you to put your website online. Without it, you would have to find a way to host your website on your own, which would be difficult and expensive. Web hosting is typically provided by web hosts, which are businesses that maintain, configure, and run physical servers that house websites.
How can I host my website?
- Hosting a website needs a server/computer with public network access or a cloud service platform that can offer the same to store your files, files that contain your webpage code, database configs or any other necessary assets.
AWS S3 Bucket for Hosting a Static Webpage
We will be using an S3 bucket to host my static portfolio web page.
Step 1: Create an S3 Bucket to Host a website
- Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/.
In the Buckets list, choose the name of the bucket that you want to enable static website hosting. Else you can create a new bucket as mentioned below.
Bucket name - user-defined (keep it unique)
AWS Region - Choose the region based on your location
- Uncheck "Block All Public Access." This is on by default to prevent objects in buckets from being visible to the open internet, which would make your bucket unreachable. AWS shows a warning that says to turn it back on unless you're using "specific and verified use case," such as static website hosting. Because that's exactly what we're doing, you can ignore this.
Keep the rest of the options default and click "Create bucket" on the bucket, and open it up.
Step 2: Upload your web page files in the bucket
Click on the upload button and choose the "Add folder" option. Navigate to your folder with webpage files and click on upload.
Step 3: Enabling static web hosting in the S3 bucket
Once everything is synced, you can configure the bucket to allow website hosting. From the properties tab, enable the "Static Website Hosting" option, and select your index file.
Look out for the "Static Website Hosting" tab and click on the Edit button
Make the necessary changes as mentioned below:
Enable Static hosting and mentioned index.html as an index document that must be present in the files which you just uploaded.
Step 4: Give read permissions to public user
- This turns on static website hosting but doesn't explicitly grant read access. To do that, you'll need to add the following bucket policy under Permissions > Bucket Policy: (In the preceding example bucket policy,
Bucket-Name
is a placeholder for the bucket name. To use this bucket policy with your own bucket, you must update this name to match your bucket name.)
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "PublicReadGetObject",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::Bucket-Name/*"
]
}
]
}
You refer to the below screenshot:
Your bucket will now be viewable from the following endpoint:
http://akshaygh-portfolio.s3-website-us-east-1.amazonaws.com
Voila! Your webpage is accessible publicly...! You can find the same in S3 bucket properties.
Great! Everything works correctly.
References: