下面以 Debian + Nginx 为例,给你讲 最常见的几种证书配置方式,从简单到生产级。
sudo apt update
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d example.com -d www.example.com
✅ Certbot 会自动:
- 申请证书
- 修改 Nginx 配置
- 配置 HTTP → HTTPS 跳转
sudo certbot renew --dry-run
Certbot 默认会通过 systemd timer 自动续期。
/etc/nginx/ssl/example.com.crt/etc/nginx/ssl/example.com.keyserver {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/nginx/ssl/example.com.crt;
ssl_certificate_key /etc/nginx/ssl/example.com.key;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
root /var/www/html;
index index.html;
}
server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}
sudo nginx -t
sudo systemctl reload nginx
sudo openssl req -x509 -nodes -days 365 \
-newkey rsa:2048 \
-keyout /etc/nginx/ssl/self.key \
-out /etc/nginx/ssl/self.crt
然后按 方式二 配置即可(浏览器会警告,属正常)。
sudo chmod 600 /etc/nginx/ssl/*.key
cat example.com.crt ca_bundle.crt > fullchain.crt
sudo ufw allow 80,443/tcp
如果你愿意,可以告诉我:
我可以直接帮你写一份 可直接用的 Nginx 配置。