首页 > 作文

免费的https证书怎么样,阿里云https配置教程

更新时间:2023-04-05 21:19:17 阅读: 评论:0

作者:hellogithub-追梦人物

http 报文以明文形式传输,如果你的网站只支持 http 协议,那么就有可能遭受到安全攻击。你可以使用 google 浏览器打开一个 http 协议网站,会发现 chrome 在网址的左边将这个网站标记为不安全。

https 为 h第一名英文ttp 报文提供了一个加密传输的通道,这样攻击者就无法窃听篮球争霸或者篡改传输的内容。要启用 https,必须向一个可信任机构申请一个 https 证书。专业的证书申请需要收费,不过对于个人博客网站来说,有很多免费的证书申请机构。比如 let’s encrypt,它提供了免费的证书申请服务,申请过程十分简单,只需要运行几条命令即可,而且证书到期后支持自动续期,可谓一劳永逸。接下来我们就是用 let’s encrypt 提供的工具来申请免费的 https 证书。

首先安装 let’s encrypt 提供的证书申请工具。登录 https://certbot.eff.org/ 选择我们博客网站使用的服务器软件和操作系统。教程中以 nginx 和 centos 7 为例:

首先安装必要工具:

$ sudo yum -y install yum-utils
$ sudo sudo yum install -y certbot python2-certbot-nginx

certbot python2-certbot-nginx 是 l500字作文大全et’s 爱国观后感encrypt 提供的 https 证书申请的工具,python2-certbot-nginx 是专门针对 nginx 的插件,使得 nginx 运行的服务申请证书更加简单方便。

然后运行证书申请命令:

$ sudo certbot --nginx

注意

经测试,运行上述命令后有可能报 importerror: no module named ‘requests.packages.urllib3’ 的错误,这是由于 requests 和 urlib3 版本过低所致(可以参考这个 issue[2] 的讨论),解决办法是重装它们,运行下面的命令:

$ pip uninstall requests
$ pip uninstall urllib3
$ yum remove python-urllib3
$ yum remove python-requests

然后重新安装 certbot,由于它依赖上面两个包,所以重装时会一并装上:

$ sudo yum install -y certbot python2-certbot-nginx

重新执行证书申请命令:sudo certbot –nginx

会有一系列交互式的提示,首先会让你输入邮箱,用于订阅。然后输入 a 同意他们的政策。

接着 certbot 会自动扫描出来域名,根据提示输入想开启 https 的域名标号:

which names would you like to activate https for

1: django-blog-tutorial-v2-demo.zmrenwu.com

lect the appropriate numbers parated by commas and/or spaces, or leave input

blank to lect all options shown (enter ‘c’ to cancel): 1

然后 certbot 会做一个域名校验,证明你对这个域名有控制权限。验证通过后,let’s encrypt 就会把证书颁发给你。

最后会提示你是否把 http 重定向到 https,当然选择是,这样 certbot 会自动帮我们修改 nginx 的配置,将 http 重定向到 https,如果用户使用 http 协议访问我们的博客网站,就会重定向到 https 协议访问,确保安全性。

plea choo whether or not to redirect http traffic to https, removing http access.

1: no redirect – make no further changes to the webrver configuration.

2: redirect – make all requests redirect to cure https access. choo this for

new sites, or if you’re confident your site works on https. you can undo this

change by editing your web rver’s configuration.

lect the appropriate number [1-2] then [enter] (press ‘c’ to cancel): 2

redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/django-blog-tutorial-v2.conf

certbot 申请的证书只有 3 个月有效期,不过没有关系,certbot 可以无限续期,我们增加一条 crontab 定时任务用来执行 certbot 自动续期任务,这样一次申请,终生使用。

打开 /etc/crontab,增加定时任务:

echo "0 0,12 * * * root python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew" | sudo tee -a /etc/crontab > /dev/null

这里配置每天 12 点执行自动续期命令。

由于全站开启了 https,因此需要把网站中非 https 的内容(比如通过 http 协议请求的外部资源)改为 https,我们的博客中目前有一处引入外部图标库的样式文件是以 http 协议引入的,需要改为 https:

ba.html

<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">

以上,简单几步,就开启了全站 https。

参考资料

[1]hellogithub-team 仓库: https://拟人句有哪些github.com/hellogithub-team/hellodjango-blog-tutorial

[2]issue: https://github.com/certbot/certbot/issues/5104

本文发布于:2023-04-05 21:18:56,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/d4dba35850c0d29d9d09b4cadf4677a4.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:免费的https证书怎么样,阿里云https配置教程.doc

本文 PDF 下载地址:免费的https证书怎么样,阿里云https配置教程.pdf

标签:证书   命令   协议   域名
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图