下面按最常见的场景给你一个清晰、可操作的 Debian + Nginx 配置 SSL 教程(以 Debian 11/12 为例,使用 Let’s Encrypt 免费证书)。
example.com)sudo apt update
sudo apt install nginx -y
启动并设置开机自启:
sudo systemctl enable nginx
sudo systemctl start nginx
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d example.com -d www.example.com
⚠️ 把
example.com换成你的真实域名
过程中会:
Certbot 会生成类似:
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
}
访问:
https://example.com
Certbot 通常已自动添加:
server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}
如没有,可手动加。
测试续期:
sudo certbot renew --dry-run
Certbot 已通过 systemd timer 自动续期,无需手动操作。
如果你已有证书:
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /path/to/fullchain.pem;
ssl_certificate_key /path/to/privkey.pem;
location / {
root /var/www/html;
index index.html;
}
}
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
/etc/letsencrypt/live/你的域名/
如果你需要:
可以告诉我你的具体使用场景,我可以直接给你对应配置。