n5321 | 2025年7月3日 11:59

Tags: blog building


Let’s Encrypt 是目前全球最常用的 免费 SSL 证书提供服务,可以让你的网站支持 https:// 访问,并获得浏览器的“安全锁🔒”标识。

Nginx 监听 443 端口 + 配置 SSL + Django 处理逻辑

ubuntu 添加

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

步骤 2:使用 certbot 自动申请证书

sudo certbot --nginx -d autoem.net -d www.autoem.net

步骤 3:修改 Nginx 配置以增强兼容性,然后测试并重启:

sudo nginx -t

sudo systemctl restart nginx


步骤 4:自动续期设置(Let’s Encrypt 有效期90天)

sudo certbot renew --dry-run


反馈:


Saving debug log to /var/log/letsencrypt/letsencrypt.log

Processing /etc/letsencrypt/renewal/autoem.net.conf

Account registered.

Simulating renewal of an existing certificate for autoem.net and www.autoem.net

Congratulations, all simulated renewals succeeded: 

  /etc/letsencrypt/live/autoem.net/fullchain.pem (success)




settings.py 推荐update
SECURE_SSL_REDIRECT = True

SESSION_COOKIE_SECURE = True

CSRF_COOKIE_SECURE = True