目录
前言
完成 WordPress 安装后,WordPress 网站与用户之间的通信是通过 HTTP(未加密)完成的。虽然 HTTP 可用于测试目的,但要在生产环境中使用,就必须切换到HTTPS。
前提条件
- Nginx
- WordPress
WordPress 和 Nginx 已经完成好配置
安装 Certbot
对于基于APT的发行版(例如Debian、Ubuntu等):
sudo apt update
sudo apt install python3 python3-dev python3-venv libaugeas-dev gcc
对于基于RPM的发行版(例如Fedora、CentOS等):
sudo dnf install python3 python-devel augeas-devel gcc
创建一个Python虚拟环境
sudo python3 -m venv /opt/certbot/
sudo /opt/certbot/bin/pip install --upgrade pip
安装 Certbot
sudo /opt/certbot/bin/pip install certbot certbot-nginx
配置 Certbot 命令
sudo ln -s /opt/certbot/bin/certbot /usr/local/bin/certbot
使用 Certbot 获取 Letsencrypt 单域名证书
sudo certbot --nginx -d www.example.com
*确保打开80端口
获取成功后,可选择让 Nginx 自动配置 HTTP 重定向 HTTPS。
使用 Certbot 获取 Letsencrypt 泛域名证书
sudo certbot certonly --manual -d *.example.com -d example.com --agree-tos --email you@example.com --no-bootstrap --manual-public-ip-logging-ok --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory
获取成功后,证书将会存储在 /etc/letsencrypt 目录下。接下来先在 WordPress 设置界面更改网址为 HTTPS,再重启 Nginx,此时再进入就会自动跳转到 HTTPS。
*请注意,获取的 Letsencrypt 免费证书有效期为3个月。
发表评论须遵守中华人民共和国相关法律法规。违规评论将会被删除。
Comments must subject to the relevant laws and regulations of the People’s Republic of China. Offending comments will be deleted.