Certbot
Certbot 是一个 ACME 客户端,用于获取 Web 服务器的 SSL 证书,使网站可以通过 HTTPS 访问。Certbot 默认从 Let's Encrypt 获取证书,这是最流行的免费 CA。
安装 Certbot
sudo zypper install python3-certbot
如果您正在使用 Apache Web 服务器,请安装此插件
sudo zypper install python3-certbot-apache
如果您正在使用 NGINX Web 服务器,请安装此插件
sudo zypper install python3-certbot-nginx
Certbot 是一个在线服务的客户端,API 可能会随时更改。我们建议使用最新的 openSUSE Leap 版本或 Tumbleweed,以获取更新的 Python 和 Certbot。最新的 Leap 通常会附带一个较旧的 Certbot,应该可以正常工作。但是,如果您遇到问题,请尝试从 openSUSE 构建服务获取最新版本
opi python3-certbot
为 Apache/NGINX 获取证书
假设您有一个网站 http://example.com/ 由 Apache/NGINX 提供支持,并且您希望为其启用 HTTPS。在运行 Certbot 之前,请确保在 /etc/apache2/vhosts.d/example.com.conf 或 /etc/nginx/vhosts.d/example.com.conf 中有有效的 Apache/NGINX 虚拟主机配置。
NGINX 不仅用于提供静态文件和运行 cgi,还用于作为代理将请求转发到 Node.js 或 Go 应用程序。NGINX 处理 SSL、IPv4/IPv6 比 Node.js 或 Go 更好。它还允许您运行多个 Web 应用程序共享相同的 80/443 端口。
运行此命令并按照说明操作,Certbot 将自动安装证书并更新 Apache/NGINX 配置
sudo certbot run
您不需要重启 Apache 或 Nginx 服务器。Certbot 会为您完成此操作!
如果您正在使用没有插件支持的其他 Web 服务器,则仅生成证书并手动配置您的 Web 服务器
sudo certbot certonly
设置自动续订
Let's Encrypt 颁发的证书将在 3 个月后过期。如果您忘记续订证书,您的网站将无法访问。如果您不想浪费时间,可以使用 systemd 定时器或 cron 作业自动运行 renew 命令。
Systemd 方法
sudo zypper install certbot-systemd-timer sudo systemctl enable certbot-renew.timer sudo systemctl start certbot-renew.timer
Cron 方法
sudo crontab -e
21 07 22 * * root /usr/bin/certbot renew
这将每天在 22:07:21 运行续订。您应该使用不同的随机时间,以避免每个人在同一时间续订并使 Let's Encrypt 服务器崩溃。
在浏览器中测试
打开您的 Web 浏览器,访问以“https://”开头的您的网站,看看网站是否正常工作。
您还可以在 SSL Labs 上测试您的网站。
内部链接
- uacme,另一个用 C 编写的 ACME
- Setup openSUSE VPS,设置 Web 服务器的其他步骤