域名证书管理

域名管理

acme.sh

Bash 复制代码
git clone https://gitee.com/neilpang/acme.sh.git

cd acme.sh

#把 acme.sh 安装到你的 home 目录下:
./acme.sh --install -m 1264218057@qq.com


#切换CA机构到letsencrypt
./acme.sh --set-default-ca --server letsencrypt


#生成相应的解析记录显示出来, 你只需要在你的域名管理面板中添加这条 txt 记录即可.
./acme.sh --issue --dns -d   local-storage.yuxuan.xyz --yes-I-know-dns-manual-mode-enough-go-ahead-please 
#这里会在对应的家目录下面生成一个.acme.sh的目录,目录下存在一个域名为名字的目录
#分别要在nginx配置fullchain.car
#域名.key
#ca.cer
 #获取证书:
./acme.sh --renew -d  local-storage.yuxuan.xyz --yes-I-know-dns-manual-mode-enough-go-ahead-please
./acme.sh --renew -d   local-storage.yuxuan.xyz --yes-I-know-dns-manual-mode-enough-go-ahead-please
./acme.sh --renew -d  local-svr2.yuxuan.xyz --yes-I-know-dns-manual-mode-enough-go-ahead-please
#更新后自动重读nginx
./acme.sh --install-cert -d local-chat.yuxuan.xyz --reloadcmd "docker exec nginx nginx -s reload"

./acme.sh --cron --home "/home/fb/.acme.sh"


 

Certbot

目前certbot管理证书主要有两种方法:

使用Nginx插件:

  • 不需要停止Nginx:使用certbot的nginx插件,无需停止或者启动nginx。cerbot会自动为nginx配置添加临时的验证规则,并在验证完成后清理这些规则
  • 自动配置SSl:除了自动验证,nginx插件还会尝试自动为域名配置ssl,包括证书和定期自动续期。
Bash 复制代码
#ubuntu20.04版本以上
#安装snapd
 apt update
 apt install certbot python3-certbot-nginx


#使用命令获取证书
#此命令获取证书并让Certbot自动编辑nginx配置
certbot --nginx   
#这个命令会自动读取nginx中的配置文件用到的域名,并申请对应的证书
#需要注意,此命令会修改证书位置。使用此命令需要确保nginx正常启动


#此命令只获取证书,手动更改nginx配置
 certbot certonly --nginxbuch #依托于nginx做验证,需要-d指定域名

#测试自动续费证书,正常续费不需要--dry-run
 certbot renew 

certbot --nginx --nginx-server-root 配置文件位置 --nginx-ctl 命令位置

旧:reception.sexpired.xyz    新:chat.signalchat.xyz
 旧:storage.sexpired.xyz    新: storage.signalchat.xyz
 

#另外一个方法
#类似standalone,自启一个web应用来申请证书并验证,需要有对应的目录修改权限
certbot certonly --webroot -w /var/www/certbot -d hub.rlbzg.xyz -d manager.rlbzg.xyz -d----
COMPOSE文件样例
  nginx:
    container_name: nginx
    image: nginx:1.24
    restart: always
    environment:
      - TZ=Asia/Shanghai
    volumes
      - /home/fb/fb-docker/nginx/certbot/conf:/etc/lstsencrypt #certbot管理证书
      - /home/fb/fb-docker/nginx/certbot/www:/var/www/certbot#certboth缓存位置
    ports:
      - "80:80"
      - "443:443"
      
      
Dockerfile需要修改:
 apt-get -y install certbot python3-certbot-nginx
 
 
 
#crontab 续期 
 0 0 1 */2 * docker exec -it nginx certbot renew --force-renewal --quiet
 && docker exec nginx nginx  -s reload

使用--standalone模式

  • 需要停止Nginx:在--standalone模式下,因为certbot将启动一个临时的web服务器来处理acme挑战验证,所以需要保证80及443未被占用
  • 手动配置ssl:使用--standalone模式成功获取证书后,还需要手动编辑nginx配置文件
Bash 复制代码
/opt/nginx/sbin/nginx -s stop# 必须先关掉nginx

#验证多个就 -d 参数来实现
certbot certonly --standalone --email 邮箱 -d 域名 -d 域名


/opt/nginx/sbin/nginx
相关推荐
武子康11 分钟前
调查研究-183 Apple container:Mac 上用轻量 VM 跑 Linux 容器,Swift 会改写本地容器体验吗?
docker·容器·apple
大树883 天前
金刚石散热越强,管路越先见顶
大数据·运维·服务器·人工智能·ai
摇滚侠3 天前
Linux CentOS7 rpm 安装 MySQL 5.7
linux·运维·mysql
霸道流氓气质3 天前
领域驱动设计(DDD)在 Spring Boot 微服务中的实践指南
运维·spring boot·微服务
Inhand陈工3 天前
基于台达PLC与映翰通IG502的智慧水产养殖精准投喂与远程运维解决方案
运维·人工智能·物联网·阿里云·信息与通信
Alsn863 天前
等待学习-学习目录:Docker 容器安全攻防
学习·安全·docker
酣大智3 天前
ARP代理--工作原理
运维·网络·arp·arp代理
shushangyun_3 天前
2026年快消品B2B系统推荐:支持终端门店订货、促销政策自动化的工具?
java·运维·网络·数据库·人工智能·spring·自动化
施努卡机器视觉3 天前
SNK施努卡侧滑门锁上滑轮总成自动化装配线,从零件到组件,全流程精密制造方案
运维·自动化·制造
AC赳赳老秦3 天前
用 OpenClaw 搭建服务器故障应急响应系统,自动处理 80% 常见运维故障
android·运维·服务器·python·rxjava·deepseek·openclaw