温馨提示×

debian nginxssl怎样免费

小樊
43
2026-10-20 06:05:29
栏目: 云计算

在 Debian 上给 Nginx 配置免费 SSL 证书,最常用、最推荐的方法是使用 Let’s Encrypt + Certbot。下面是详细步骤:


一、准备工作

  1. 一台 Debian 服务器(已安装 Nginx)
  2. 一个已解析到服务器 IP 的域名(如 example.com)
  3. 能使用 80 端口(Certbot 验证需要)

二、安装 Certbot

sudo apt update
sudo apt install certbot python3-certbot-nginx -y

三、自动申请并配置 SSL(最简单)

sudo certbot --nginx -d example.com -d www.example.com
  • Certbot 会自动:
    • 申请免费证书
    • 修改 Nginx 配置
    • 开启 HTTPS
    • 设置 HTTP 跳转 HTTPS

四、手动指定 Nginx 站点(可选)

如果你已配置好 Nginx:

sudo certbot --nginx

按提示选择域名即可。


五、测试自动续期

Let’s Encrypt 证书 90 天过期,Certbot 会自动续期:

sudo certbot renew --dry-run

六、Nginx SSL 配置示例(Certbot 自动生成)

server {
    listen 80;
    server_name example.com;
    return 301 https://$host$request_uri;
}

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;

    location / {
        root /var/www/html;
        index index.html;
    }
}

七、常见问题

1. 端口被占用

确保:

sudo ufw allow 80
sudo ufw allow 443

2. 域名未解析

ping example.com

3. 证书失败

查看日志:

sudo certbot certificates
journalctl -u nginx

八、其他方法(不推荐)

  • 自签名证书(浏览器不信任)
  • 第三方免费证书(如 ZeroSSL,需手动)

✅ 总结:
Debian + Nginx 免费 SSL = Let’s Encrypt + Certbot,一条命令搞定。

如果你愿意,我可以帮你:

  • 写完整 Nginx 配置
  • 配置多域名
  • 配置自动 HTTPS 强制跳转

直接说你的域名和用途即可。

0 踩