在Debian系统上配置Nginx以使用Let’s Encrypt SSL证书,可以按照以下步骤进行:
1. 安装Certbot
Certbot是一个自动化的工具,用于获取和续订Let’s Encrypt证书。你可以使用以下命令安装Certbot:
sudo apt update
sudo apt install certbot python3-certbot-nginx
2. 获取SSL证书
使用Certbot获取SSL证书。运行以下命令并按照提示操作:
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
-d yourdomain.com和-d www.yourdomain.com是你的域名。- Certbot会自动检测Nginx配置文件并提示你进行必要的更改。
3. 配置Nginx
Certbot会自动修改你的Nginx配置文件以启用SSL。通常,配置文件位于 /etc/nginx/sites-available/yourdomain.com 和 /etc/nginx/sites-enabled/yourdomain.com。
你可以手动检查这些文件,确保它们包含以下内容:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name yourdomain.com www.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
root /var/www/html;
index index.html index.htm;
location ~ /\.ht {
deny all;
}
}
4. 测试Nginx配置
在重新加载Nginx之前,测试配置文件是否有语法错误:
sudo nginx -t
如果一切正常,你会看到类似以下的输出:
nginx: configuration file /etc/nginx/nginx.conf test is successful
5. 重新加载Nginx
重新加载Nginx以应用新的配置:
sudo systemctl reload nginx
6. 自动续订证书
Certbot会自动设置一个cron作业来定期续订证书。你可以手动测试续订过程:
sudo certbot renew --dry-run
如果没有错误,证书将会被续订,并且Nginx配置会自动更新。
7. 配置防火墙
确保你的防火墙允许443端口的流量:
sudo ufw allow 'Nginx Full'
8. 验证SSL配置
使用浏览器访问你的域名,确保HTTPS连接正常,并且证书有效。
通过以上步骤,你应该能够在Debian系统上成功配置Nginx以使用Let’s Encrypt SSL证书。
以上就是关于“Nginx SSL在Debian如何配置Let's Encrypt”的相关介绍,筋斗云是国内较早的云主机应用的服务商,拥有10余年行业经验,提供丰富的云服务器、租用服务器等相关产品服务。云服务器资源弹性伸缩,主机vCPU、内存性能强悍、超高I/O速度、故障秒级恢复;电子化备案,提交快速,专业团队7×24小时服务支持!
简单好用、高性价比云服务器租用链接:https://www.jindouyun.cn/product/cvm