在Debian系统上配置LNMP(Linux, Nginx, MySQL, PHP)的SSL证书,通常需要以下几个步骤:
-
获取SSL证书:
- 你可以从Let’s Encrypt免费获取SSL证书。
- 使用Certbot工具可以自动化这个过程。
-
安装Certbot:
sudo apt update sudo apt install certbot python3-certbot-nginx
-
获取并安装SSL证书:
- 运行Certbot来获取证书:
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
- Certbot会自动配置Nginx并重启服务以应用新的SSL设置。
- 运行Certbot来获取证书:
-
验证配置:
- 确保Nginx配置文件中没有错误:
sudo nginx -t
- 如果没有错误,重新加载Nginx服务:
sudo systemctl reload nginx
- 确保Nginx配置文件中没有错误:
-
自动续期:
- Certbot会设置一个cron任务或systemd定时器来自动续期证书。
- 你可以手动测试续期过程:
sudo certbot renew --dry-run
- 如果一切正常,Certbot会自动续期证书。
详细步骤
1. 获取SSL证书
使用Certbot获取SSL证书:
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
Certbot会提示你输入电子邮件地址,并同意Let’s Encrypt的服务条款。然后它会自动配置Nginx并重启服务。
2. 验证配置
确保Nginx配置文件中没有错误:
sudo nginx -t
如果没有错误,重新加载Nginx服务:
sudo systemctl reload nginx
3. 自动续期
Certbot会设置一个cron任务或systemd定时器来自动续期证书。你可以手动测试续期过程:
sudo certbot renew --dry-run
如果一切正常,Certbot会自动续期证书。
注意事项
- 确保你的域名解析正确,指向你的服务器IP地址。
- 如果你使用的是防火墙,确保开放443端口(HTTPS)。
- 定期检查证书的有效期,并确保自动续期功能正常工作。
通过以上步骤,你可以在Debian系统上成功配置LNMP的SSL证书。