生成证书
首先我们需要安装 nginx 我们使用 Letsencrypt的 letsencrypt-auto脚本 现在centos7已经不支持了 1 2 3 4 5 6 7 8 9 10 11 # english Skipping bootstrap because certbot-auto is deprecated on this system. Your system is not supported by certbot-auto anymore. Certbot cannot be installed. Please visit https://certbot.eff.org/ to check for other alternatives. # chinese 跳过引导程序,因为在此系统上不推荐使用 certbot-auto。 certbot-auto 不再支持您的系统。 无法安装 Certbot。 请访问 https://certbot.eff.org/ 查看其他替代方案。
certbot-auto不再支持所有的操作系统!根据作者的说法,certbot团队认为维护certbot-auto在几乎所有流行的UNIX系统以及各种环境上的正常运行是一项繁重的工作,加之certbot-auto是基于python 2编写的,而python 2即将寿终正寝,将certbot-auto迁移至python 3需要大量工作,这非常困难,因此团队决定放弃certbot-auto的维护。 既然如此,现在我们还能继续使用certbot吗?certbot团队使用了基于snap的新的分发方法。
我的环境 CentOS 7安装letsencrypt but 在安装letsencrypt之前,需要先安装epel 和snaps。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 yum install -y epel-release yum install -y snapd systemctl enable --now snapd.socket ln -s /var/lib/snapd/snap /snap snap install core snap refresh core
卸载已安装的certbot 通过snap安装certbot 1 snap install --classic certbot
创建/snap/bin/certbot的软链接,方便certbot命令的使用 1 ln -s /snap/bin/certbot /usr/bin/certbot
letsencrypt的使用 获取证书。 确保nginx处于运行状态,需要获取证书的站点在80端口,并且可以正常访问。
生成证书 1 certbot certonly --nginx --email 你的邮箱 -d 你的域名 -d 你的域名
配置Nginx文件 在上面的生成证书执行完毕之后会打印证书文件路径 复制这两条路径在nginx文件中配置 1 2 /etc/letsencrypt/live/你的域名/fullchain.pem /etc/letsencrypt/live/你的域名/privkey.pem
我的nginx配置文件 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { listen 443 ssl; server_name 你的域名 www.你的域名; ssl_certificate /etc/letsencrypt/live/www.ryder.pw/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/www.ryder.pw/privkey.pem; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location / { root html; index index.html index.htm; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } server { listen 80; server_name ryder.pw www.ryder.pw; location / { rewrite ^(.*)$ https://$host$1 permanent; } } }