温馨提示×

Debian域名如何实现自动续费

小樊
36
2025-03-06 22:27:43
栏目: 云计算
Debian服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在 Debian 系统上实现域名自动续费,通常涉及到 SSL 证书的自动续期。以下是使用 Certbot 和 acme.sh 实现自动续期的步骤:

使用 Certbot 实现自动续期

Certbot 是一个常用的工具,用于自动获取和安装 Let’s Encrypt 的证书,并支持自动续期。以下是详细步骤:

  1. 安装 Certbot
sudo apt update
sudo apt install certbot
  1. 为服务器申请证书
sudo certbot certonly --manual --preferred-challenges=dns --email your-email --server https://acme-v02.api.letsencrypt.org/directory -d your-domain
  1. 配置服务器

编辑 Nginx 配置文件,例如:

server {
    listen 443 ssl;
    server_name your-domain.com;
    ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
    location / {
        root /var/www/html;
        index index.html;
    }
}
  1. 重启 Nginx
sudo systemctl restart nginx
  1. 设置定时任务(Cron Job)
sudo crontab -e

添加以下行,每天检查一次证书并续期:

0 3 * * * certbot renew --quiet

使用 acme.sh 实现自动续期

acme.sh 是一个开源的 ACME 客户端,可以实现 SSL 证书的自动续期。以下是详细步骤:

  1. 安装 acme.sh
mkdir -p /etc/acme/{config,live,certs}
mkdir -p /var/www/acme/.well-known/acme-challenge
chown -R username /var/www /etc/acme
git clone https://github.com/acmesh-official/acme.sh.git /etc/acme/acme.sh
  1. 配置 acme.sh
/etc/acme/acme.sh --install -m your@email.com --home /etc/acme --config-home /etc/acme/config --cert-home /etc/acme/certs
source ~/.bashrc
  1. 开启 acme.sh 自动更新
/etc/acme/acme.sh --config-home '/etc/acme/config' --upgrade --auto-upgrade
  1. 添加 Nginx 配置给 acme.sh

创建并修改 /etc/nginx/acme.conf 文件:

location /.well-known/acme-challenge/ {
    alias /var/www/acme/.well-known/acme-challenge/;
}

修改需要添加 SSL 证书的域名 Nginx 配置文件:

server {
    listen 80;
    listen [::]:80;
    server_name demo.com;
    include /etc/nginx/acme.conf;
    location / {
        return 301 https://$server_name$request_uri;
    }
}
  1. 重新启动 Nginx
sudo nginx -s reload
  1. 添加定时任务
crontab -e

添加以下行,每小时检查一次证书并续期:

0 * * * * "/etc/acme/acme.sh" --cron --home "/etc/acme" --config-home "/etc/acme/config" > /dev/null

通过以上步骤,您可以在 Debian 系统上实现域名的自动续费,确保您的网站始终使用有效的 SSL 证书。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:debian域名怎么续费

0