| 关键词:证书 Https |
为什么要部署 说到底,就是 https 更安全。甚至为了安全,一个专业可靠的网站, https 是必须的。如今,没有部署 Https 的网站,无论是 Chrome 还是 Firefox,都会将其标记为醒目的不安全网站。Https 的网站,还能够防止 DNS 被劫持,注入广告。所以,为什么不呢? 什么是 Lets Encrypt Lets Encrypt是一个免费,自动化和开放的证书颁发机构(CA),为公众的利益而运行。它是由Internet Security Research Group(ISRG)提供的服务。 其为用户提供所需的数字证书,以便以最友好的方式免费为网站启用 HTTPS(SSL / TLS)。我们这样做是因为我们想要创建一个更安全,更尊重隐私的 Web。 Lets Encrypt背后的关键原则是:
Cerbot 就是Lets Encrypt提供的客户端 安装 CertbotCertbot 是一个易于使用的自动客户端,可为您的 Web 服务器提取和部署 SSL / TLS 证书。Certbot 由 EFF 和其他人开发,作为Lets Encrypt的客户端,Certbot 还将与支持 ACME 协议的任何其他 CA 一起使用。 虽然有许多其他客户端实施 ACME 协议来获取证书,但 Certbot 是最广泛的客户端,可以自动配置您的 Web 服务器以立即开始通过 HTTPS 提供服务。对于 Apache,它还可以选择性地自动执行安全任务,例如调整密码套件和启用重要的安全功能,例如 HTTP→HTTPS 重定向,OCSP 装订,HSTS 和升级不安全请求。 Certbot 是 EFF 加密整个互联网的更大努力的一部分。网站需要使用 HTTPS 来保护网络。与 HTTPS Everywhere 一起,Certbot 旨在建立一个结构更私密,更安全且受到保护以防止审查的网络。 Cenos 7/RHEL 7 安装 安装 Certbot 打包在 EPEL(企业 Linux 的额外包)中。要使用 Certbot,必须先 启用 EPEL 存储库。在 RHEL 或 Oracle Linux 上,还必须启用可选通道。 rpm 安装EPEL $ sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm yum 安装EPEL $ sudo yum -y install epel-release 直接下载EPELrepo $ sudo wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo 注意: 如果您在 EC2 上使用 RHEL,则可以通过运行以下命令启用可选通道: $ sudo yum -y install yum-utils $ sudo yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional 安装 Cerbot 您可以通过运行以下命令安装 Certbot: $ sudo yum install certbot Fedora 26 +安装 安装 Certbot 是为您的操作系统打包的,因此安装它只需运行以下命令: $ sudo dnf install certbot Ubuntu 安装 安装 在 Ubuntu 系统上,Certbot 团队维护PPA。将它添加到存储库列表后,您需要做的就是获取以下包。 $ sudo apt-get update $ sudo apt-get install software-properties-common $ sudo add-apt-repository ppa:certbot / certbot $ sudo apt-get update $ sudo apt-get install certbot 部署证书安装证书
$ sudo certbot certonly --webroot -w /var/www/abc -d abc.com -d www.abc.com -w /var/www/xyz -d xyz.cn -d m.xyz.cn
Alias /.well-known/acme-challenge/ "/var/www/html/.well-known/acme-challenge/"
location /.well-known/acme-challenge/ {
root /var/www/html/;
}
3 .如果您想使用Lets Encrypt的新 ACMEv2 服务器中的一个插件来发布通配符证书,您还需要在命令行中包含以下标志: --server https://acme-v02.api.letsencrypt.org/directory
$ cd /etc/letsencrypt/live $ tree . . |-- abc.com | |-- cert.pem -> ../../archive/abc.com/cert2.pem | |-- chain.pem -> ../../archive/abc.com/chain2.pem | |-- fullchain.pem -> ../../archive/abc.com/fullchain2.pem | |-- privkey.pem -> ../../archive/abc.com/privkey2.pem | `-- README `-- xyz.cn |-- cert.pem -> ../../archive/xyz.cn/cert2.pem |-- chain.pem -> ../../archive/xyz.cn/chain2.pem |-- fullchain.pem -> ../../archive/xyz.cn/fullchain2.pem |-- privkey.pem -> ../../archive/xyz.cn/privkey2.pem `-- README 2 directories, 10 files
通配符安装 获取证书 $ sudo certbot certonly -d *.domain.com --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator manual, Installer None Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org Obtaining a new certificate Performing the following challenges: dns-01 challenge for yiranzai.top - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - NOTE: The IP of this machine will be publicly logged as having requested this certificate. If youre running certbot in manual mode on a machine that is not your server, please ensure youre okay with that. Are you OK with your IP being logged? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: y - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please deploy a DNS TXT record under the name _acme-challenge.domain.com with the following value: pZDS3qjcuA-W3begyk3T-s_WW70SmewfblJ5vlfImr0 Before continuing, verify the record is deployed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Press Enter to Continue 这个时候千万不要敲enter。 配置 txt 记录,做 DNS 验证 ![]() 查看效果 $ dig -t txt _acme-challenge.domain.com @8.8.8.8 ; <<>> DiG 9.10.3-P4-Ubuntu <<>> -t txt _acme-challenge.domain.com @8.8.8.8 ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 61275 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 512 ;; QUESTION SECTION: ;_acme-challenge.domain.com. IN TXT ;; ANSWER SECTION: _acme-challenge.domain.com. 599 IN TXT "pZDS3qjcuA-W3begyk3T-s_WW70SmewfblJ5vlfImr0" ;; Query time: 246 msec ;; SERVER: 8.8.8.8#53(8.8.8.8) ;; WHEN: Wed Sep 19 11:01:52 DST 2018 ;; MSG SIZE rcvd: 113 注意第 15 行的 txt 值,与上面得到的一致。 回到获取命令,敲下enter Before continuing, verify the record is deployed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Press Enter to Continue Waiting for verification... Resetting dropped connection: acme-v02.api.letsencrypt.org Cleaning up challenges IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/domain.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/domain.com/privkey.pem Your cert will expire on 2018-12-18. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Lets Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le 搞定 配置 Nginx 这里看下nginx的配置方法,apache我就不举例说明了 顺便默认把http重定向到https server {
listen 80;
server_name abc.com;
location / {
rewrite ^(.*) https://$host$1 permanent;
}
}
server {
listen 443;
server_name abc.com;
root /var/www/abc;
ssl on;
ssl_certificate /etc/letsencrypt/live/abc.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/abc.com/privkey.pem;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHellA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
try_files $uri $uri/ /index.html;
}
}
重启服务,大功告成 $ sudo systemctl reload nginx.service 自动续订手动 可以将 Certbot 配置为在证书过期之前自动续订证书。由于Lets Encrypt证书持续 90 天,因此最好利用此功能。您可以通过运行以下命令来测试证书的自动续订: $ sudo certbot renew --dry-run 如果这看起来工作正常,您可以通过添加运行以下命令的cron 作业或systemd 计时器 来安排自动续订: $ sudo certbot renew 注意: 如果您正在设置cron或systemd作业,建议每天运行两次(在您的证书到期或续订之前,它将不会执行任何操作,但定期运行它会使您的站点有机会保持在线状态案例 a 由于某种原因,我们发生了加密启动的撤销。请在一小时内随机选择续订任务。 Crontab配置 $ sudo crontab -e 0 0,12 * * * python -c import random; import time; time.sleep(random.random() * 3600) && certbot renew 管理证书如果你是通配符证书,自然不用更新证书的域名。这里自然是为非通配符用户准备的. 重新创建和更新现有的证书 即使您已拥有具有某些相同域名的现有证书,也可以使用certonly或run子命令请求创建单个新证书。 如果请求证书run或certonly指定已存在的证书名称,Certbot将更新现有证书。否则,将创建新证书并为其指定指定的名称。 的--force-renewal,--duplicate和--expand选项控制Certbot的行为重新创建具有相同名称作为现有证书证书时。如果您未指定请求的行为,Certbot可能会询问您的意图。 --force-renewal告知Certbot请求与现有证书具有相同域的新证书。必须通过明确指定每个域-d。如果成功,此证书将与之前的证书一起保存,并且live将更新符号链接(引用)以指向新证书。这是续订特定个人证书的有效方法。 --duplicate告诉Certbot使用与现有证书相同的域创建单独的,不相关的证书。此证书与前一个证书完全分开保存。大多数用户在正常情况下不需要发出此命令。 --expand告知Certbot使用包含所有旧域和一个或多个其他新域的新证书更新现有证书。使用该--expand选项,使用该-d选项指定所有现有域和一个或多个新域。 例: certbot --expand -d existing.com,example.com,newdomain.com 如果您愿意,可以单独指定域,如下所示: certbot --expand -d existing.com -d example.com -d newdomain.com 考虑使用--cert-name而不是--expand,因为它可以更好地控制修改哪个证书,并允许您删除域以及添加域。 --allow-subset-of-names如果只能获得某些指定的域授权,则告知Certbot继续生成证书。如果证书中指定的某些域不再指向此系统,这可能很有用。 每当您以上述任何方式获得新证书时,新证书与以前获得的任何证书一起存在,无论以前的证书是否已过期。产生对多种速率限制新的证书数目是旨在防止ACME协议的滥用,如所描述的 在这里。 更改证书的域名 --cert-name通过使用-dor --domains标志指定新域,该标志还可用于修改证书包含的域。如果证书example.com 以前包含example.com和www.example.com,它可被修改以仅包含example.com通过仅指定example.com与-d或--domains标志。例: certbot certonly --cert-name example.com -d example.com 以上操作删除了www.example.com 可以使用相同的格式来扩展证书包含的域集,或者完全替换该集: certbot certonly --cert-name example.com -d example.com example.org,www.example.org 以上操作删除了www.example.com,添加了www.example.org和example.org。 撤销证书 如果您的帐户密钥已被盗用或者您需要撤销证书,请使用该revoke命令执行此操作。请注意,该revoke命令采用证书路径(以结尾cert.pem),而不是证书名称或域。例: certbot revoke --cert-path /etc/letsencrypt/live/CERTNAME/cert.pem 您还可以使用该reason标志指定撤消证书的原因。原因包括:unspecified这是默认的,以及keycompromise, affiliationchanged,superseded,和cessationofoperation: certbot revoke --cert-path /etc/letsencrypt/live/CERTNAME/cert.pem --reason keycompromise 此外,如果证书是通过--stagingor --test-cert标志获得的测试证书,则该标志必须传递给 revoke子命令。撤销证书后(或其他证书管理任务),可以使用delete子命令从系统中删除所有证书的相关文件: certbot delete --cert-name example.com 原文 https://blog.yiranzai.cn/posts/22912/ 请大家收藏保存,用电脑看。或者访问原文链接 历史优秀文章: 环境搭建 - Yum安装lanmp svn搭建 - SVN搭建使用 数据库主从复制 - Mysql主从复制 数据库读写分离 - 基于MyCAT实现读写分离 数据库主主复制并基于MyCAT实现高可用 - MySQL主主复制并基于MyCAT实现高可用 MySQL分组查询TOP N的实践和踩坑 - MySQL分组查询TOP N的实践和踩坑 |
| 本文出处: https://www.toutiao.com/a6631741506921169421/ |
|
声明:文章版权归原作者所有 部分文章转自互联网 如有侵权请联系
[邮箱地址] 删除
|