Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deploy personal blogs to cloud platforms using Serverless Framework

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

How to use Serverless Framework to deploy personal blog to the cloud platform, many novices are not very clear about this. In order to help you solve this problem, the following editor will explain it in detail. People with this need can come and learn. I hope you can get something.

Tencent Cloud services involved in this practice

Serverless Framework

COS (object Storage)

API Gateway

DNSPod domain name registration, domain name filing, domain name resolution

SSL certificate

CDN (content delivery Network)

Domain name purchase and filing

In 2021-01-21, the domain name serverlesslife.cn was purchased from DNSPod (acquired by Tencent in 2011) and verified by its real name.

After purchasing a domain name, in Chinese mainland, to use the domain name to provide services, you also need to record the domain name.

An application for filing was submitted on "Tencent Cloud website filing" Mini Program on 2021-1-31.

After two rounds of audit (Tencent Cloud audit + Bureau audit), it was approved on 2021-02-07 eight days later.

Introduction to Serverless Framework

Serverless Framework is a popular Serverless framework launched by serverless.com, which can deploy Serverless functions / applications to different cloud vendors' Serverless platforms. In China, Tencent Cloud has reached a strategic cooperation with serverless.com, made a lot of customizations and made many components, making it easy to deploy Serverless functions / applications to Tencent Cloud.

Use Hugo to build a personal blog

To build a personal independent blog, there are many open source site-building tools available, such as WordPress, Hexo, Jekyll, Hugo and so on.

Because I have used Hugo before and like it more, I use Hugo to build a personal blog here.

Hugo is a static website generator implemented by Go language. Simple, easy to use, efficient, easy to scale, rapid deployment.

Hugo is easy to expand means that it has a wide range of topics to choose from, which is one of the reasons why I like it. Everyone can choose their favorite theme.

After the initialization of the Hugo site, the theme was selected among the many themes: LoveIt (what a beautiful name! ).

The theme also has many parameters that can be configured on demand according to your own needs.

After the basic framework is built, if you want to write a blog post, you only need to add Markdown files and related static resource files.

Hugo supports local real-time preview, and you can view the results in real time through a browser while writing markdown files.

Of course, when deployed to a production server, it needs to be compiled, and the task of compiling to a site can be completed with a hugo command.

The site source code is hosted on GitHub: https://github.com/serverlesslife-cn/serverlesslife

Also use GitHub Actions to synchronize the code to Gitee: https://gitee.com/serverlesslife/serverlesslife

Deployment site

After the site is compiled, you can deploy it to Tencent Cloud using Serverless Framework CLI.

Serverless Framework CLI requires a configuration file, serverless.yml, which reads as follows:

Component: website # (required) refers to the name of component. Currently, the tencent-website component name: serverlesslife-2021 # (required) the instance name created by the website component app: serverlesslife-2021 # (optional) the website application name stage: prod # (optional) is used to distinguish environment information. The default value is devinputs: src: src:. / public index: index.html region: ap-guangzhou bucketName: serverlesslife-2021 protocol: https

Where the public directory is the directory where the site files are located after hugo compilation.

Use the serverless deploy command for deployment, and if you do not configure secretid and secretkey on the local .env, you need to use Wechat for scanning login.

During deployment, a bucket is created in COS and the files under the public directory are uploaded to the bucket, and then the access address of a Tencent Cloud level 4 domain name is generated. The bucket prefix is serverlesslife-2021, and the tool will automatically add the APPID of the Tencent Cloud account as the suffix.

Under the Serverless Framework console, there will be an application named serverlesslife-2021, which will have an access address for Tencent Cloud level 4 domain name, as shown below:

On the bucket list page stored by the COS object, you can see that there is a bucket named serverlesslife-2021-1259061164, as follows:

Custom domain name + SSL certificate + automatic refresh CDN

To configure "Custom Domain name + SSL Certificate + Auto Refresh CDN", you need to add some configuration information to serverless.yml. The entire serverless.yml file is as follows:

Component: website # (required) refers to the name of component. Currently, the tencent-website component name: serverlesslife-2021 # (required) the instance name created by the website component app: serverlesslife-2021 # (optional) the website application name stage: prod # (optional) is used to distinguish between environment information The default value is devinputs: src: src:. / public index: index.html region: ap-guangzhou bucketName: serverlesslife-2021 protocol: https hosts:-host: serverlesslife.cn autoRefresh: true # enable automatic CDN refresh to quickly update and synchronize the site content displayed in the accelerated domain name onlyRefresh: false # it is recommended to configure this parameter to true after the first deployment, that is, ignore other CDN configurations Only refresh operation https: switch: on http2: on certInfo: certId: 'kBM9GLPt'

The above configuration file supports the configuration of multiple domain names, and other information can be configured under each domain name, such as SSL certificate ID, automatic refresh CDN, and so on.

If you need to configure a SSL certificate when using a custom domain name, you must use CDN because the certificate can be configured under CDN.

You need to apply for a SSL certificate in the SSL Certificate console in advance. A free certificate is applied here. The certificate is valid for one year. After the application is successful, there will be an ID:kBM9GLPt, as shown below:

After configuring the information related to the domain name, Serverless Framework does a lot of things after deployment, which greatly simplifies the configuration cost.

If you don't use Serverless Framework, you need to configure it back and forth in multiple places on the console that do not use cloud services.

Let's take a look at what Serverless Framework does behind configuring "Custom Domain name + SSL Certificate":

1. Under the CDN console, go to Certificate Management-> configure certificates to associate domain names with certificates, as shown below:

2. Under the CDN console, add domain name management-> add domain name, add a new record, enable static acceleration for serverlesslife.cn, use COS static website as source site, and generate CNAME:

3. Under the COS console, click serverlesslife-2021-1259061164 bucket, and you will also see a record in the "Domain name transfer and Management"-> Custom CDN accelerated domain name:

At this point, to access the domain name normally, you also need to manually configure the domain name resolution: open the DNSPod console, add a CNAME record for the serverlesslife.cn, and the record value is the CNAME:serverlesslife.cn.cdn.dnsv1.com generated by CDN.

Note: after the first deployment, configure the onlyRefresh parameter to true, that is, ignore other CDN configurations and only refresh, otherwise the deployment time will be relatively long.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report