Backblaze B2 is a cloud storage service that allows you to store and serve static web content. Cloudflare, on the other hand, is a content delivery network (CDN) that helps to speed up and secure your website. By combining the power of Backblaze B2 and Cloudflare, you can serve your static webpages efficiently and ensure a better user experience.
When you set up a static website on Backblaze B2, the default URL to access your content is in the form of a bucket origin, like https://bucketname.backblazeb2.com. However, it would be much better if you could use your own domain name to access the content, like https://www.yourdomain.com. In this article, we will guide you through the process of serving a static webpage with Backblaze B2 and Cloudflare, so your domain name appears instead of the bucket origin.
Prerequisites
Before we begin, make sure you have the following:
- A Backblaze B2 account with a bucket containing your static web content.
- A Cloudflare account with your domain added and DNS settings configured.
Step 1: Create a CNAME Record
The first step is to create a CNAME record in your Cloudflare DNS settings. This record will map your domain to the Backblaze B2 bucket origin. Here's how you can do it:
- Login to your Cloudflare account and navigate to the DNS settings for your domain.
- Click on the "Add Record" button.
- Choose "CNAME" as the record type.
- In the "Name" field, enter the subdomain you want to use for your static content (e.g., "www").
- In the "Target" field, enter your Backblaze B2 bucket origin URL (e.g., "bucketname.backblazeb2.com").
- Click the "Save" button to create the CNAME record.
It may take some time for the DNS changes to propagate. Once the changes are propagated, you should be able to access your static content using your domain name.
Step 2: Configure Cloudflare Page Rules
Now that you have created the CNAME record, it's time to configure Cloudflare Page Rules to ensure that your domain name appears in the browser address bar instead of the bucket origin. Follow these steps:
- Login to your Cloudflare account and navigate to the "Page Rules" section.
- Click on the "Create Page Rule" button.
- In the "URL Matches" field, enter your domain name (e.g., "yourdomain.com/*").
- Under "Settings," choose "Forwarding URL" as the action.
- In the "Destination URL" field, enter your Backblaze B2 bucket origin URL followed by
$1(e.g., "https://bucketname.backblazeb2.com/$1"). - Make sure to enable the "Forwarding URL" toggle.
- Click the "Save" button to create the page rule.
With these page rules in place, whenever someone accesses your domain, Cloudflare will automatically fetch the content from the Backblaze B2 bucket and serve it under your domain name.
Step 3: Test and Troubleshoot
Once you have completed the above steps, it's time to test and troubleshoot if necessary. Here are a few things you can check:
- Clear your browser cache and try accessing your domain to see if the static content is served correctly.
- If you encounter any issues, double-check your DNS settings and page rules in Cloudflare.
- Wait for any DNS changes to fully propagate, as it may take some time.
If everything is set up correctly, your static webpage should now be served with your own domain name instead of the Backblaze B2 bucket origin.
Conclusion
Serving a static webpage with Backblaze B2 and Cloudflare is a great way to ensure fast and reliable content delivery. By following the steps outlined in this article, you can easily get your domain name to appear instead of the bucket origin. Enjoy serving your static content with improved performance and a better user experience!
References
| Reference | Link |
|---|---|
| Backblaze B2 | https://www.backblaze.com/b2/cloud-storage.html |
| Cloudflare | https://www.cloudflare.com/ |