Nginx + Certbot配置 HTTPS / SSL 证书(简化版已测试)

前提条件:

1.已有域名

2.Nginx 已安装并正在运行,且有对应的 Server 配置,在nginx.conf 中配置好80(http)

3.防火墙开放 80 和 443 端口

powershell 复制代码
#安装certbot
yum install certbot -y

#安装python-certbot-nginx
yum install python-certbot-nginx -y

#签发证书,替换你的域名yourdomain
certbot --nginx -d yourdomain

#检查 Certbot 版本
certbot --version	

重启nginx:

powershell 复制代码
systemctl restart nginx

测试 Certbot 自动续期:

powershell 复制代码
certbot renew --dry-run

真实续订(正式用):

powershell 复制代码
certbot renew

该命令会检查所有即将过期的证书,并尝试续订。注意:在使用完签发命令后,需重新nginx使站点ssl配置生效。

自动续订(计划任务用):

powershell 复制代码
#该命令可以将续订命令添加到crontab计划任务中,以实现自动续订,并重启nginx。
certbot renew --quiet --renew-hook 'sudo systemctl reload nginx'

#假设crontab计划任务会在每月1号执行1次续订命令,并在续订后重载Nginx配置,具体示例如下。
0 0 1 * * certbot renew --quiet --renew-hook 'sudo systemctl reload nginx' > /dev/null 2>&1
相关推荐
成空的梦想6 分钟前
ZLibrary反爬机制实战分析的技术文章大纲
网络协议·https·ssl
2501_9159090633 分钟前
不用越狱就看不到 iOS App 内部文件?使用 Keymob 查看和导出应用数据目录
android·ios·小程序·https·uni-app·iphone·webview
困惑阿三3 小时前
全栈服务器运维终极备忘录
运维·服务器·nginx·pm2
小庄梦蝶3 小时前
Mixed Content: The page at ‘https://域名/‘ was loaded over HTTPS
网络协议·http·https
PascalMing4 小时前
告别 Nginx!ASP.NET Core 实现多域名 Vue 静态服务与代理转发
vue.js·nginx·asp.net
深念Y4 小时前
Nginx和Spring Cloud Gateway
运维·服务器·网络·网关·nginx·spring cloud·微服务
困惑阿三4 小时前
全栈部署排雷手册:从 405 报错到飞书推送成功
服务器·前端·后端·nginx·阿里云·node.js·飞书
yy552714 小时前
Nginx 性能优化与监控
运维·nginx·性能优化
2501_9160074721 小时前
HTTPS 抓包的流程,代理抓包、设备数据线直连抓包、TCP 数据分析
网络协议·tcp/ip·ios·小程序·https·uni-app·iphone
2501_915918411 天前
iOS mobileprovision 描述文件管理,新建、下载和内容查看
android·ios·小程序·https·uni-app·iphone·webview