Static websites have several advantages over dyanamic websites.
If you are running your personal blog or portfolio or small websites. Static websites is the way to go.
Although, this post is not for listing benefits of static website. I will write more on this in another post.
- You have AWS account
- You have cloudflare account (Free account)
Configure S3 bucket
- Create an S3 bucket with the name of your website say: www.gyanblog.com
- After creating bucket, goto bucket. Then, click on Properties.
- Click on Static website hosting. Click on first option: Use this bucket to host a website
In index document, put index.html (the starter or homepage html file)
In Error document, put the html file like 404.html
- Save it.
- Click on Permission tab
Click on bucket policy. In the editor, type below:
Remember to replace your bucket name in Resource above.
Note: It will now show your bucket as Public access. You require to have this bucket public read access.
non www bucket
Note, for SEO purpose you would want your website to open on either www. version or non-www version.
Create another bucket with non-www version, say: gyanblog.com
Again, goto Public tab on this bucket. Put above policy in Bucket policy. (Exactly same, except bucket name)
Note: the non-www bucket above.
- Goto Static website hosting tab
- Click on Redirect requests
- In target bucket or domain, type your domain name with www, and protocol https.
Note: We will have our website to open on https protocol. With cloudflare free SSL support.
Copy Website files
Now, copy your website files over ot this bucket.
Test your URL for s3 bucket website
Note down your URL from static website hosting tab. Try opening that URL in browser. You should see your website.
If you are not seeing expected result. You should see above steps carefully.
Proceed only when you see your website above.
I assume you have registered on cloudflare free account, and added your website.
- Goto DNS tab.
- If you are doing it for first time. Delete all records there.
- Add a CNAME record with name as www, and value as URL of your bucket. Remove http:// in the begining and ending slash at the end of your bucket URL.
- Add a CNAME record with name as @, and value as URL of your non-www bucket.
DNS changes in your registrar end
From where you purchased your domain, goto its DNS setting. And, change its nameservers as mentioned in DNS tab of cloudflare. In my case,
Wait for few minutes, to allow DNS changes to be done. It should be done with in 10 minutes. But, in some cases, it might take hours.
Now, if you open your website name. You would see your static website pages.
Hope you enjoyed the post.