当前位置: 首页 > backend >正文

使用Docker申请Let‘s Encrypt证书

1、安装Docker

# 安装Docker
https://docs.docker.com/get-docker/# 安装Docker Compose
https://docs.docker.com/compose/install/# CentOS安装Docker
https://mp.weixin.qq.com/s/nHNPbCmdQs3E5x1QBP-ueA

2、申请Let's Encrypt证书

详见:
https://docs.linuxserver.io/general/swag
https://github.com/linuxserver/docker-swag
https://hub.docker.com/r/linuxserver/swag

创建目录:

mkdir letsencrypt
cd letsencrypt

创建docker-compose.yaml文件:

services:swag:image: linuxserver/swag:latestcontainer_name: swagcap_add:- NET_ADMINenvironment:- PUID=0- PGID=0- TZ=Asia/Shanghai- URL=example.com- VALIDATION=http- SUBDOMAINS=www, #optional- CERTPROVIDER= #optional- DNSPLUGIN=cloudflare #optional- PROPAGATION= #optional- EMAIL= #optional#- ONLY_SUBDOMAINS=false #optional- ONLY_SUBDOMAINS=true #optional- EXTRA_DOMAINS= #optional- STAGING=false #optional- DISABLE_F2B= #optional- SWAG_AUTORELOAD= #optional- SWAG_AUTORELOAD_WATCHLIST= #optionalvolumes:- ./config:/configports:- 443:443- 80:80 #optionalrestart: unless-stopped
说明:
1、根据实际情况修改PUID、PGID的值,使用id命令来查看当前用户的PUID、PGID的值
2、根据实际情况修改URL、SUBDOMAINS的值,URL为域名、SUBDOMAINS为子域名
3、将ONLY_SUBDOMAINS的值设置为true,只获取子域名证书
参数说明:-p 443:443	HTTPS 端口。
-p 80	HTTP端口(HTTP 验证和 HTTP -> HTTPS 重定向所需)。
-e PUID=1000	UserID。
-e PGID=1000	GroupID。
-e TZ=Etc/UTC	指定要使用的时区。
-e URL=example.com	域名/DNS(example.com 或者 customsubdomain.example.com)。
-e VALIDATION=http	使用Certbot验证方法,选项为http或dns。
-e SUBDOMAINS=www,	子域名(逗号分隔,无空格),如www,ftp,cloud。对于通配符证书,设置为wildcard。
-e CERTPROVIDER=	可选地定义证书提供商。设置zerossl为 ZeroSSL 证书(需要现有的ZeroSSL 帐户EMAIL和在环境变量中输入的电子邮件地址)。否则默认为 Let's Encrypt。
-e DNSPLUGIN=cloudflare	如果VALIDATION设置为dns。
-e PROPAGATION=	可选择覆盖(以秒为单位)dns 插件的默认传播时间。
-e EMAIL=	用于证书到期通知的可选电子邮件地址(ZeroSSL 必需)。
-e ONLY_SUBDOMAINS=false	如果您希望只获取某些子域的证书,而不是主域的证书(主域可能托管在另一台机器上,无法验证),请将其设置为true。
-e EXTRA_DOMAINS=	额外的完全限定域名(以逗号分隔,无空格),如example.net、subdomain.example.net、*.example.org。
-e STAGING=false	设置为true以在暂存模式下检索证书。速率限制会更高,但生成的证书将无法通过浏览器的安全测试。仅用于测试目的。
-e DISABLE_F2B=	如果您已经在其他地方运行该服务或使用不同的 IPS,则设置true为禁用容器中的 Fail2ban 服务。
-e SWAG_AUTORELOAD=	设置为true,以便在配置文件发生更改时自动重新加载,而无需停止/重启 nginx。您的文件系统必须支持 inotify。此功能之前通过 modtrue提供。
-e SWAG_AUTORELOAD_WATCHLIST=	除以下文件夹外,还包含一个管道分隔的用于自动重新加载的附加文件夹列表:/config/nginx。
-v /config	持久配置文件。
--read-only=true	使用只读文件系统运行容器。
--cap-add=NET_ADMIN	需要 fail2Ban 才能修改 iptables 规则。

创建并启动容器:

docker-compose up -d

查看容器列表:

docker ps

查看日志:

docker logs swag

进入容器:

docker exec -it swag bash

重启容器:

docker restart swag

停止并销毁容器:

docker-compose down

删除镜像:

docker rmi linuxserver/swag:latest

删除目录:

rm -rf ./config

SSL证书文件:

# 证书路径:
./config/etc/letsencrypt/live/域名# 证书文件:
cert.pem -> ../../archive/域名/cert1.pem
chain.pem -> ../../archive/域名/chain1.pem
fullchain.pem -> ../../archive/域名/fullchain1.pem
priv-fullchain-bundle.pem
privkey.pem -> ../../archive/域名/privkey1.pem
privkey.pfx
README# README文件:
This directory contains your keys and certificates.`privkey.pem`  : the private key for your certificate.
`fullchain.pem`: the certificate file used in most server software.
`chain.pem`    : used for OCSP stapling in Nginx >=1.3.7.
`cert.pem`     : will break many server configurations, and should not be usedwithout reading further documentation (see link below).WARNING: DO NOT MOVE OR RENAME THESE FILES!Certbot expects these files to remain in this location in orderto function properly!We recommend not moving these files. For more information, see the Certbot
User Guide at https://certbot.eff.org/docs/using.html#where-are-my-certificates.# 说明:
私钥文件:privkey.pem
证书文件:fullchain.pem

创建./config/nginx/proxy-confs/域名.subdomain.conf文件:

详见:./config/nginx/proxy-confs/homepage.subdomain.conf.sample
server {listen 443 ssl;listen [::]:443 ssl;server_name 域名;#include /config/nginx/ssl.conf;client_max_body_size 0;location / {root /config/www;#include /config/nginx/proxy.conf;#include /config/nginx/resolver.conf;#set $upstream_app homepage;#set $upstream_port 3000;#set $upstream_proto http;#proxy_pass $upstream_proto://$upstream_app:$upstream_port;}
}

重启nginx服务:

# 重启nginx服务:
docker exec -it swag nginx -s reload# curl访问:
curl -L 域名

浏览器访问:

3、详见

https://mp.weixin.qq.com/s/vNwwniGxGcKTPKKNJjYjfg
https://www.linuxserver.io/
https://docs.linuxserver.io/general/swag
https://github.com/linuxserver/docker-swag
https://hub.docker.com/r/linuxserver/swag
https://github.com/linuxserver-archive/docker-letsencrypt
https://hub.docker.com/r/linuxserver/letsencrypt
https://mp.weixin.qq.com/s/SOjKZ7ekufLVJ_dmfKwjZQ
http://www.xdnf.cn/news/13590.html

相关文章:

  • xilinx的GT配置说明(二)
  • 【HTTP重定向与缓存机制详解】
  • 芯伯乐XBLW GT712选型及应用设计指南
  • Spring Cloud业务相关问题
  • 姜伟生《统计至简》
  • 宏基因测序宿主污染太严重,无解?
  • 御微半导体面试总结
  • UE5.2像素流实现公网访问
  • 40.第二阶段x64游戏实战-封包-添加发包功能
  • 13.react与next.js的特性和原理
  • LangChain MCP Adapters Quickstart
  • 无人机避障——感知篇(基于ZED2实现Vins Fusion)
  • [原创](现代Delphi 12指南):[macOS 64bit App开发]: SameText, SameStr, 比较字符串更简单
  • Git 介绍、安装以及基本操作
  • 【行云流水AI笔记】游戏里面的强化学习使用场景
  • 博客系统自动化测试
  • Linux基本指令(包含vim,用户,文件等方面)超详细
  • 服务器BMC相关问题-重启-挂起-HANG
  • java超大文件上传
  • 【评测】flux-dev文生图模型初体验
  • 股指期货贴水率怎么计算?
  • 知识图谱和图数据库Neo4j
  • AI的发展过程:深度学习中的自然语言处理(NLP);大语言模型(LLM)详解;Transformer 模型结构详解;大模型三要素:T-P-G 原则
  • APP Trace 传参安装流程详解 (开发者视角)
  • Flotherm许可的跨平台兼容性
  • 在RK3588上部署ROS2与ORB-SLAM3实现Gazebo小车自主导航-环境搭建过程
  • 6月11日day51打卡
  • 机器学习与深度学习18-线性代数01
  • Java八股文——Spring「MyBatis篇」
  • RPC启动机制及注解实现