debian

Debian LNMP如何配置SSL证书

小樊
82
2025-02-18 00:56:25
栏目: 云计算

在Debian系统上配置LNMP(Linux, Nginx, MySQL, PHP)的SSL证书,通常需要以下几个步骤:

  1. 获取SSL证书

    • 你可以从Let’s Encrypt免费获取SSL证书。
    • 使用Certbot工具可以自动化这个过程。
  2. 安装Certbot

    sudo apt update
    sudo apt install certbot python3-certbot-nginx
    
  3. 获取并安装SSL证书

    • 运行Certbot来获取证书:
      sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
      
    • Certbot会自动配置Nginx并重启服务以应用新的SSL设置。
  4. 验证配置

    • 确保Nginx配置文件中没有错误:
      sudo nginx -t
      
    • 如果没有错误,重新加载Nginx服务:
      sudo systemctl reload nginx
      
  5. 自动续期

    • Certbot会设置一个cron任务或systemd定时器来自动续期证书。
    • 你可以手动测试续期过程:
      sudo certbot renew --dry-run
      
    • 如果一切正常,Certbot会自动续期证书。

详细步骤

1. 获取SSL证书

使用Certbot获取SSL证书:

sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

Certbot会提示你输入电子邮件地址,并同意Let’s Encrypt的服务条款。然后它会自动配置Nginx并重启服务。

2. 验证配置

确保Nginx配置文件中没有错误:

sudo nginx -t

如果没有错误,重新加载Nginx服务:

sudo systemctl reload nginx

3. 自动续期

Certbot会设置一个cron任务或systemd定时器来自动续期证书。你可以手动测试续期过程:

sudo certbot renew --dry-run

如果一切正常,Certbot会自动续期证书。

注意事项

通过以上步骤,你可以在Debian系统上成功配置LNMP的SSL证书。

0
看了该问题的人还看了