Designing a Personal Website Architecture on Cloud Services
This post describes how to build a personal website cleanly and cheaply on top of a range of cloud services. The cloud products involved include cloud servers, SSL, business email, object storage, CDN, cloud functions, API Gateway, and cloud monitoring.
Overview
Cloud providers now offer a large number of services covering compute, networking, storage, and more. Some of these products are powerful, and used well they can greatly reduce development and operations costs. Below I use my personal website, built on Tencent Cloud, as an example to walk through the overall architecture.
Right now the site mainly serves my personal blog, and other applications such as a personal cloud drive can be added later. The current architecture:

1. Infrastructure
1. Cloud server (CVM)
The cloud server is a CVM instance with 1 core, 2 GB of memory, and 1 Mbps of downstream bandwidth. That configuration is fully adequate for a personal blog in its early days, and student plans or promotional pricing make it fairly cheap.
With a server in place, the blog can be set up. I chose the minimalist Typecho blogging system; the installation process is covered in this post. It mainly involves installing nginx, MySQL, PHP, and the Typecho source on the server.
2. Domain
Registration - ICP filing - DNS resolution
A server is assigned a public IP when it is created, but to make the site easy to share and spread, I recommend registering a domain. After registration the domain needs ICP filing. The filing process has been simplified so it can be done in a mini program, which drops the old step of being photographed in front of a backdrop, and the whole filing takes about 1-2 weeks. After that, set up DNS resolution in the console, that is, bind the domain to the server IP. Note that both the www and non-www versions of the domain need to be resolved. Once resolution is done, the site can be reached in a browser through the domain.
Choosing a primary domain
For SEO, I recommend picking one primary domain based on personal preference, because search engines treat addresses with and without the www prefix as two separate sites when calculating ranking weight. Websites in China usually use www, while sites abroad (such as GitHub, Stack Overflow, and LeetCode) do not. I chose the address without www (zhayujie.com) and configured nginx to 301-redirect requests for the www address to the non-www one, to consolidate ranking weight.
Business email
A domain also makes it possible to register a business email service with your own domain as the suffix. The basic edition is free with no limit on the number of accounts, so running out of email addresses (for example when registering on the WeChat Official Accounts Platform) is no longer a concern. Addresses look like zyj@zhayujie.com.
3. Site-wide HTTPS
For security and SEO, I recommend serving the site over HTTPS. A free SSL certificate can be requested; place the certificate and private key on the server, then enable and configure SSL in nginx. Likewise, to avoid splitting ranking weight, HTTP requests can be 301-redirected to HTTPS. On my site, for example, requests with or without www, over HTTP or HTTPS, all end up at https://zhayujie.com/.
2. Image Hosting with COS and CDN
1. Object storage (COS)
The server's downstream bandwidth is limited, so if images are stored on our own server, concurrent access may exceed the bandwidth and slow the site down. Instead, images can be stored in COS (Cloud Object Storage) to build a self-managed image host. This also makes it easier to manage image resources in one place when the blog is synced to other blogging platforms.
COS is fairly simple to use and works much like a cloud drive: a bucket can hold a tree of directories. Each bucket is assigned a public domain, and the files in it are accessed as https://{bucket}/{dir}/{filename}. Using that link directly in the blog is a bad idea, though. Once we migrate to another cloud provider or switch to a different storage method, the original links break, and fixing them one by one costs too much. Fortunately, COS supports custom domains, so files can be accessed through an address like http://{domain}/{dir}/{filename}.
2. Content delivery network (CDN)
The custom origin domain of COS does not support HTTPS. To keep the whole site on HTTPS while also speeding up access and reducing traffic costs, COS can be paired with the CDN service by enabling a custom CDN acceleration domain. See the documentation for the detailed steps.
A subdomain can serve as the custom CDN domain, with a CNAME record added for it. Requests to the custom domain then go to a CDN edge server first and fall back to the origin, COS, on a cache miss. For example, the image above is served from https://blog.cos.zhayujie.com/web/blog-cloud-arch.jpg.
3. A Serverless Messaging Service
1. Cloud Functions (SCF)
Building a blog involves a number of message-sending features: notifying me when a reader replies to a post, notifying a reader when I reply to their comment, notifying subscribed readers when a new post is published, and so on. This kind of notification feature is well suited to being split out into a standalone messaging service. Written into the blog source, it would be hard to reuse (other applications on the site would have to reimplement it to send messages), while deploying it as a separate service adds operations overhead (what happens if the service goes down?). This is where a serverless architecture is worth considering: only the core code snippets are handed over to the cloud provider to host.
Tencent Cloud offers SCF cloud functions (Serverless Cloud Function), a FaaS technology. Asynchronous, stateless features like message notifications are a good fit for cloud functions, for example sending an email to a specified recipient whenever a request comes in.
2. API Gateway
Cloud functions can be triggered in several ways, the most common being scheduled tasks and API Gateway. Since message notifications are triggered by events rather than on a schedule, I chose API Gateway. Once the trigger is created, the function can be called directly from the public internet, much like an nginx reverse proxy.
The API Gateway domain is randomly generated, which does not hold up well as things change, so I bound a custom domain here as well and trigger functions through addresses of the form https://{domain}/{function}. For example, my email-sending function is configured at https://apigw.zhayujie.com/commentNotice, and the business code only needs to send a POST request to that address to trigger email delivery.
4. Monitoring, Snapshots, and Analytics
1. Monitoring and alerts
Server monitoring and alerting are just as important, since they help us catch and troubleshoot problems in time. Monitoring is usually viewed directly in the console under CVM - Instances - Monitoring, which shows detailed CPU, memory, bandwidth, disk, and other data across different time ranges and granularities.
Alerts are configured in Cloud Monitor. A variety of alarm policies can be set up, such as alerting when CPU, memory, bandwidth, or other metrics exceed a threshold, as well as on machine failure events (such as ping unreachable or a machine restart). Alerts for COS can be configured there too. Alerts can be delivered through WeChat, email, and SMS.
2. Snapshots
To protect the data on the server's disk from attacks or accidental deletion, snapshot backups can be set up in the CVM - Snapshots console. Scheduled snapshot policies are also supported, which automatically create a new snapshot at a set interval.
3. Traffic analytics
Analyzing how the site is visited helps us improve its content and experience. For traffic statistics I use Baidu Tongji, integrated through tracking code. It shows each visitor's region, referrer, search terms, conversions, and other information, along with traffic trends.
For search engine tooling I use Baidu Webmaster Tools, which is used to submit pages for indexing and to view data such as index counts and crawl frequency.
Summary
That covers building a fully featured personal blog. As a rough estimate of the cost: a cloud server bought during a promotion is about 100 yuan a year, a domain usually costs a few dozen yuan, and products like COS, CDN, and SCF all come with generous free quotas. Traffic costs are negligible in the early days of a site as well, so overall the cost is extremely low. Individual developers can treat their personal website as a product and think about how to make good use of the various public cloud products to improve the user experience, raise development efficiency, and cut operations costs.
2 comments
Leave a Comment
- Previous: MIT 6.828 -- Lab 1: Unix Utilities
- Next: Serverless Architecture Explained
深度好文
:-)