在 Debian 上配置 Nginx + SSL(通常免费用 Let’s Encrypt)一般步骤如下:
sudo apt update
sudo apt install nginx -y
安装完成后:
sudo systemctl status nginx
浏览器访问服务器 IP,能看到 Nginx 默认页即成功。
Debian 官方源已包含 certbot:
sudo apt install certbot python3-certbot-nginx -y
你的域名(如 example.com)A 记录必须指向该服务器 IP。
sudo certbot --nginx -d example.com -d www.example.com
按提示输入邮箱、同意协议即可。
Certbot 会自动:
sudo certbot renew --dry-run
Let’s Encrypt 证书 90 天有效,Debian 默认会通过 systemd timer 自动续期。
如果你使用自有证书:
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/ssl/certs/example.com.crt;
ssl_certificate_key /etc/ssl/private/example.com.key;
location / {
root /var/www/html;
index index.html;
}
}
server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}
sudo ufw allow 'Nginx Full'
如果你需要:
可以告诉我你的使用场景。