目前web传送加密,通用的加密方法是使用https,https需要证书,证书分免费和收费2种,参考文章 https://www.aliyun.com/product/cas?utm_content=se_1513054
|
支持域名 |
价格 |
有效期 |
Symantec是 SSL/TLS 证书 |
保护1个通配符域名的同级所有子域名
|
¥ 34000(收费便宜)
|
1年 |
中国金融认证中心(CFCA)证书 |
通配符 |
12750元(收费最高) |
1年 |
Let's Encrypt |
通配符 (多个域名) 均支持 |
0 |
3个月(到期可以脚本自动续) |
阿里云免费证书 |
3个域名 |
0 |
1年 |
推荐使用Let's Encrypt证书。
Nginx 实现 HTTPS(基于 Let's Encrypt 的免费证书)
下文为centos下使用证书教程
1. 安装 Let’s Encrypt 客户端
所有的证书相关的操作,都可以通过 Certbot 软件实现。
注意:HTTPS 作为重要的基础服务,一旦出问题就需要立刻把软件更新到官网提供的最新版本,所以不推荐用各个 Linux 发行版的默认仓库进行安装,而是通过官方工具 certbot-auto 安装。
wget https://dl.eff.org/certbot-auto # 下载到本地
chmod a+x ./certbot-auto # 添加可执行权限
./certbot-auto --help all # 查看帮助
2. 生成证书,-d 可以多个域名,注意防火墙80和443端口必须允许访问,确保 所有人可以访问这个 .well-known 文件 因为等下webroot会在你的服务器端创建一个这样的文件 并通过80段端口来访问它,确定这个域名确实是你的 。
certbot-auto --nginx -d test.youxr.cn
按照提示信息操作即可。也可以指定目录下载验证文件
certbot-auto certonly --webroot -w /data/www/youxr -d www.youxr.cn
证书生成的路径为:/etc/letsencrypt/live/www.youxr.cn/fullchain.pem
使用dns验证: certbot-auto certonly -d "*.youxr.cn" --manual --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory
3.配置监听https
server{
listen 80;
server_name test.youxr.cn;
#return 301 https://$server_name$request_uri; //是否转发http请求
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/test.youxr.cn/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/test.youxr.cn/privkey.pem; # managed by Certbot
}
4.配置系统自动更新证书
在linux系统定时程序增加自动更新证书脚本
#更新https证书
1 3 1 * * /usr/local/bin/certbot-auto renew
Apache支持https配置
<VirtualHost *:443>
DocumentRoot /www/youxr.cn
ServerName www.youxr.cn:443
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/youxr.cn/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/youxr.cn/privkey.pem
</VirtualHost>
更详细文档 可参考:https://certbot.eff.org/