You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel): 输入自己的邮箱地址
(A)gree/(C)ancel: 输入 A,同意
(Y)es/(N)o: 输入 Y 确认
Please enter in your domain name(s) (comma and/or space separated) (Enter 'c' to cancel): 输入要部署 HTTPS 的域名
最后得到结果:
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/dev.fmtech.me/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/dev.fmtech.me/privkey.pem
Your cert will expire on 2018-06-21. To obtain a new or tweaked
version of this certificate in the future, simply run certbot-auto
again. To non-interactively renew *all* of your certificates, run
"certbot-auto renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
云主机:nginx https 配置
接上一篇 云主机:用户登陆配置。
配置目标:
安装 nginx
使用
yum info nginx
查看到仓库源里的 nginx 版本是 1.12.2,最新稳定版。就安装这一个。去阿里云的控制台,将这个主机实例的 80 端口和 433 端口打开。
使能 nginx 服务,启动:
此时,在我们本机的浏览器就可以访问主机的公网 ip 地址了。得到的结果是 nginx 的欢迎页:
证明 nginx 安装成功。
为域名生成证书
我们希望全站走 HTTPS。使用 Let’s Encrypt 。有一套工具放在 [github][https://github.com/certbot/certbot] 上。
我们先在云主机上安装 git:
下载 letencrypt 工具:
先停止 nginx 服务,再生成证书:
它会安装 python 环境和一些信赖包。有三个交互操作:
Is this ok [y/d/N]: y
输入 y 确认安装Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel):
输入自己的邮箱地址(A)gree/(C)ancel:
输入 A,同意(Y)es/(N)o:
输入 Y 确认Please enter in your domain name(s) (comma and/or space separated) (Enter 'c' to cancel):
输入要部署 HTTPS 的域名最后得到结果:
生成的证书存放在
/etc/letsencrypt/live/dev.fmtech.me/
目录下。SSL 配置文件
先生成一个 dhparam.pem 文件,用于 HTTPS 中的密钥交换。
这一步比较耗时。
创建 SSL 配置文件,其中会指定 dhparam.pem 的位置。
在 /etc/nginx/snippets/ssl-params.conf 文件中添加如下内容:
nginx 配置 HTTPS
注释掉
/etc/nginx/nginx.conf
中的 80 端口默认配置。在
/etc/nginx/conf.d/
创建我们的配置:内容如下:
这个配置的第一段,是把所有 HTTP 请求都转发给同一域名的 HTTPS。
第二段处理 HTTPS 请求。测试一下配置文件是否正确:
重启 nginx 服务:
在本地机器浏览器里访问:dev.fmtech.me,会自动跳转到
https://dev.fmtech.me/
,说明配置成功。在 ssllabs 里对本域名作个 SSL 安全测试。得到 A+ 则说明配置成功了。
证书自动更新
Let’s Encrypt 好在免费,但每个证书的有效其只有 90 天,快过期时执行下面的命令即可更新:
该命令会检查是否有必要更新证书。只有在快过期时才会真正执行更新。
使用 cron 工具来让这个检查工作定期自动执行,这里每周一凌晨一点执行一次,并于 5 分钟后重启 nginx:
添加两行:
cron 的配置保存于 /var/spool/cron/root。
重启 crond 服务:
参考
The text was updated successfully, but these errors were encountered: