2020-05-13 18:30:47
Let’s Encrypt 的服务相信很多人都知道了,我个人认为这是最好的免费 SSL 服务。下面内容即使如何在自己的网站上使用 Let’s Encrypt 实现 SSL.
前提条件
自己拥有一个域名,备案了的域名最好。Ubuntu 16.04 的服务器,你可以到腾讯云或者阿里云购买这样的云主机。
将域名自己解析到你的 Ubuntu 16.04 的云主机 ip;注意如果你的域名没备案,在购买主机的时候,推荐大家购买腾讯云或者阿里云境外的主机。
Certbot 其实就是维护 Let’s Encrypt 的 Package,在 Ubuntu 16.04 上,我们可以这样安装:
首先安装 Nginx:
sudo apt-get install nginx
以上过程,等待安装完毕就好。
然后添加 package repository
sudo add-apt-repository ppa:certbot/certbot
这个过程中,等待验证完毕,按下 ENTER 就好。然后更新 apt 源数据:
sudo apt-get update
最后,安装 Certbot 的 Nginx package:
sudo apt-get install python-certbot-nginx
安装完 Nginx 和 Certbot 之后,需要简单配置 Nginx 以便于 Let’s Encrypt 能起作用:
sudo vi /etc/nginx/sites-available/default
使用 vi 编辑器打开 /etc/nginx/sites-available/default,可以直接删除里面的所有内容,然后再添加下面的配置:
server {
listen 80;
listen [::]:80;
server_name your-domain.com www.your-domain.com;
}
注意这里的 your-domain.com 换成你自己的域名。
保存退出之后,执行以下命令来检测 Nginx 的配置文件是否有错:
sudo nginx -t
如果出现类似 syntax ok 这样的语句,就说明 Nginx 的配置文件没有问题。之后就是重新加载 Nginx 的配置文件了:
sudo service nginx reload
前面的两大步配置完成,就可以使用 Let’s Encrypt 签发 SSL 证书了:
sudo certbot --nginx -d your-domian.com -d www.your-domain.com
注意这里的 your-domain.com 换成你自己的域名。
如果你第一次运行 certbot 命令的话,你需要在弹出的窗口输入你的邮箱地址还有需要接受 Let’s Encrypt 的协议,这样之后,你大概会看到下面的文字:
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
-------------------------------------------------------------------------------
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):
在上面这里选择 1 或者 2,我推荐大家直接选择 2,因为这个会直接将你的 nginx 文件配置好并且是会将 http 跳转到 http 的。
选择完毕之后,等待 SSL 生成完毕,就会有类似这样的输出:
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at
/etc/letsencrypt/live/your-domain.com/fullchain.pem. Your cert will
expire on 2017-12-29. To obtain a new or tweaked version of this
certificate in the future, simply run certbot again with the
"certonly" option. To non-interactively renew *all* of your
certificates, run "certbot renew"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: http://letsencrypt.org/donate
Donating to EFF: http://eff.org/donate-le
然后在上面的文字中,这个 /etc/letsencrypt/live/your-domain.com/fullchain.pem 路径很重要,就是你的 SSL 证书路径。
其实到这里,访问 your-domain.com 应该就可以看到 http 的效果了。
因为 Let’s Encrypt 签发的 SSL 证书有效期只有 90 天,所有在过期之前,我们需要自动更新 SSL 证书,而如果你使用最新的 certbot 的话,Let’s Encrypt 会帮你添加自动更新的脚本到 /etc/cron.d 里,你只需要去检测一下这个命令是否生效就OK!
sudo certbot renew --dry-run
如果这个命令你没看到什么 error 的话,那就是没什么问题了。
本文主要是介绍了在 Ubuntu 16.04 的云服务器上,使用 Nginx 作为服务器软件情况下,如何配置 Let’s Encrypt 的 SSL 证书,使得网站得以支持 http 的过程。内容很浅,但是我觉得还是挺有用的。
Ubuntu系统配置samba实现文件夹共享
06-22
Ubuntu 16.04安装Docker Compose及简单的使用示例
05-21
Bash使用示例(1) – 数组
04-28
Docker命令行参考(4) – docker inspect显示容器或镜像相关信息
07-19
管理swarm(3) – swarm实践 – 环境准备
07-18
Ubuntu下迁移通过apt安装的MysQL数据库文件目录
07-18
Ubuntu操作系统出厂状态恢复后,如何设置启动界面
05-25
Docker run参考(1) – 一般格式
05-13
Docker run参考(8) – 退出状态码
05-15
Docker命令行参考(11) – docker load从tar归档文件或sTDIN导入镜像
07-20
Docker命令行参考(14) – docker attach附着到一个运行中的容器
07-19
Docker命令行参考(2) – dockerd启动docker daemon
05-03
Docker命令行参考(6) – docker commit提交容器的更改创建新镜像
07-15
IdeaPad Y460p&Y560p用户手册
07-12
Portal3.x&Portal4.x&Portal5.x&Portal6.x私密文件柜帮助文档及常见问题
06-10
centos7.3下配置LAMP部署WordPress博客
07-04
Debian 7 (Wheezy)安装配置Apache mod_fastcgi PHP-FPM
07-20
Jenkins运行多个步骤的配置
06-21
centos 7 yum安装配置apache 2.4
07-15
常见问题 ThinkCentre Windows Vista 操作系统中没有内置TPM(国家半导体信任模块)1.1 驱动程序而且 Windows Update 站点也未提供此驱动程序,可以从何处下
05-06
File Encryption XP下载
1.64MB
下载MiNiEncrypt v7.1 免费版
2.7M
下载KeyManager(SSL证书管理工具) v4.4.19 官方版
110MB
下载scenicplayer(异步播放的软件)V2.11.15.0 官方版
5.8M
下载sniffer pro下载
40.59 MB
下载swf播放器(sWF文件播放器)v6.0.0.3 官方版
2.5MB
下载Wise Force DeLeter
1.8M
下载activesync下载
22.72MB
下载biospwds下载
127.1K
下载cs1.6下载
141MB
下载deadpixeltest下载
0.16MB
下载easyrecovery pro下载
87.8M
下载fireworks下载
88.4M
下载flash cs4下载
164.2M
下载flashfxp(FXP/FTP软件)v5.4.0.3970 免费版
4.06MB
下载gghost一键恢复(系统备份还原工具)v10.03.09 中文版
14.5M
下载multisim10(电路仿真工具)2021 免费版
224.80MB
下载onekeyghost(备份还原工具)v14.5.8 绿色版
6.09MB
下载pcsx2模拟器(游戏模拟器)v1.5.0 免费版
12.9M
下载NewFiLetime(文件时间修改软件) v3.99 中文版
186KB
下载