5

为站点添加把锁

 3 years ago
source link: https://blog.mute-g.com/post/hugo/how-to-set-https.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

为了增强自己站点的安全性,同时提高站点在互联网中的权重,决定利用AWS的服务为站点提供SSL/TSL证书(https)。

  • 已经掌握如何利用S3服务托管静态网站。
  • 已经拥有自己的域名。
  • 希望为自己的域名添加安全证书,可以通过https访问自己的静态网站。

在AWS Certificate Manager(ACM)申请证书

为自己的域名申请证书。比如blog.mute-g.com
注意,必须在“美国东部(弗吉尼亚北部)”区域申请。否则在CloudFront中无法使用。

在AWS CloudFront Manager(CF)建立分发(Distributions)

Step 1: Select delivery method

  • delivery method选择“Web”。

Setp 2: Create distribution

Origin Settings

  • Origin Domain Name选择托管成静态网站的S3存储桶。比如blog.mute-g.com

Distribution Settings

  • Alternate Domain Names(CNAMEs)里面填写要进行关联的域名,比如blog.mute-g.com
  • SSL Certificate选择Custom SSL Certificate,然后在下拉框中选择之前在ACM申请的证书。

点击Create Distribution

需要一段时间才能完成配置,等待Status变成Deployed
这时可以看到Domain Name列下面有一个xxxxx.cloudfront.net,这个地址下一步会用到。

去自己的域名托管商的管理页面,进行DNS设定。

  • 添加一个CNAME,将自己的域名比如blog.mute-g.com的目标设置成上一步记下来的xxxxx.cloudfront.net
  • 需要一点时间让所有设置生效。
  • 之后,可以通过http://blog.mute-g.com访问网站。
  • 如果使用https://blog.mute-g.com则会看到浏览器的地址栏前面出现了一个小锁头啦。

让http请求自动跳转到https

  • 在CloudFront Distributions一览页面选中自己的站点,点击Distribution Settings按钮。
  • Behaviors标签,点击Create Behavior,新建一个Redirect HTTP to HTTPS类型的条目。
  • 等待设置生效后,当我们通过http://blog.mute-g.com访问网站时,会自动跳转到https://blog.mute-g.com

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK