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
相关推荐
我有毓毓症2 小时前
nginx作业
运维·nginx
q***71852 小时前
海康威视摄像头RTSP使用nginx推流到服务器直播教程
运维·服务器·nginx
qq_3168377515 小时前
初步压测的 nginx反向代理 到 Spring Cloud网关 到 Spring Cloud微服务的网络参考配置
nginx·spring cloud·微服务
SakitamaX17 小时前
nginx
运维·nginx
2301_7644413320 小时前
Streamlit搭建内网视频通话系统
python·https·音视频
小坏讲微服务21 小时前
Nginx集群与SpringCloud Gateway集成Nacos的配置指南
spring boot·nginx·spring cloud·gateway
2501_915918411 天前
HTTP和HTTPS工作原理、安全漏洞及防护措施全面解析
android·http·ios·小程序·https·uni-app·iphone
2501_915918411 天前
uni-app iOS日志管理实战,从调试控制台到系统日志的全链路采集与分析指南
android·ios·小程序·https·uni-app·iphone·webview
Jerry2505091 天前
微信小程序必要要安装SSL证书吗?小程序SSL详解
网络·网络协议·网络安全·微信小程序·小程序·https·ssl
驯狼小羊羔1 天前
学习随笔-http和https有何区别
前端·javascript·学习·http·https