要在Debian上更新Nginx SSL证书,请按照以下步骤操作:
sudo apt-get update
sudo apt-get install certbot python3-certbot-nginx
yourdomain.com
替换为您的域名:sudo certbot --nginx -d yourdomain.com
Certbot将自动配置Nginx并启用HTTPS。它还会创建一个新的Nginx配置文件,通常位于/etc/letsencrypt/options-ssl-nginx.conf
。
/etc/nginx/nginx.conf
,并找到以下行:include /etc/nginx/sites-enabled/*;
确保此行没有被注释掉(没有分号;
)。
sites-enabled
目录中,找到您的域名配置文件。如果不存在,请创建一个。确保配置文件包含以下内容,用您的域名替换yourdomain.com
:server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://$host$request_uri;
}
}
sites-enabled
目录:sudo ln -s /etc/letsencrypt/options-ssl-nginx.conf /etc/nginx/sites-enabled/default-ssl.conf
sudo nginx -t
sudo systemctl reload nginx
现在,您的Nginx服务器应该已经使用新的SSL证书。请注意,Certbot通常会为证书设置一个90天的有效期。因此,您需要定期(例如每90天)运行sudo certbot --nginx -d yourdomain.com
命令以更新证书。