
Certbot Standalone 申请SSL证书3分钟拿证80端口被占也有解法【免费下载链接】certbotCertbot is EFFs tool to obtain certs from Lets Encrypt and (optionally) auto-enable HTTPS on your server. It can also act as a client for any other CA that uses the ACME protocol.项目地址: https://gitcode.com/gh_mirrors/ce/certbot机器上 80 端口已被别的程序占着或者根本就没装 Web 服务器现在又必须尽快拿到一张 Lets Encrypt 证书——这是 Certbot Standalone 模式的典型场景。它自己临时起一个 HTTP 服务完成 http-01 域名验证一条命令几分钟内完成签发验证结束自动释放端口。什么时候该用 Standalone什么时候别用Standalone 是 Certbot 内置的认证器之一不依赖任何现有 Web 服务它在自己进程内开一个临时 TCP 监听在/.well-known/acme-challenge/路径下响应验证请求挑战完成后即关闭实现见certbot/src/certbot/_internal/plugins/standalone.py。它适合三类场景机器上没装 Nginx/Apache 的临时服务器、Docker 宿主机、CI 构建机有 Web 服务但能在几分钟内停掉的机器端口冲突 申请证书 时不想改 Web 服务器配置它不适合通配符域名仅支持 http-01官方插件描述明确写了 wildcards not supported以及 80 端口长期被占、既停不掉服务、又无法做端口转发的机器——后者应改用 dns-01。认证方式机制挑战类型典型场景standalone自建临时 HTTP 服务http-01 (80)无Web服务器、端口冲突 申请证书webroot往现有站点目录写文件http-01 (80)Web 服务持续运行、目录可写dns-01改 DNS TXT 记录dns-01通配符、80 完全不可达前提条件运行 certbot 需要 root 权限默认监听 80 低于 102480 端口必须允许互联网入站访问云服务器要同时配好系统防火墙和安全组。最小可跑流程一条命令拿证执行申请certbot certonly --standalone -d example.com \ --email adminexample.com \ --agree-tos \ --non-interactive # certonly只申请证书不动 Web 服务器配置 # --standalone由 Certbot 临时监听 80 端口完成验证 # 不指定密钥类型时默认 ECDSA / secp256r1参数说明-d域名可重复多个--email注册与到期通知邮箱首次申请必填--agree-tos同意 Lets Encrypt 服务条款--non-interactive跳过交互提示适合脚本验证成功标志输出末尾出现Successfully received certificate.且提示证书已存入/etc/letsencrypt/live/example.com/。确认证书文件certbot certificates会打印该证书的 Domains、Expiry DateLets Encrypt 有效期 90 天和证书目录。/etc/letsencrypt/live/example.com/下可见cert.pem服务器证书、fullchain.pem证书中间 CAWeb 服务器通常配这个和privkey.pem私钥。80 端口被占了怎么办绑定 80 端口失败时源码里的处理逻辑分两种端口被占EADDRINUSE会提示Could not bind TCP port 80 because it is already in use by another process on this system权限不足EACCES会提示you dont have the appropriate permissions解法就是换 root 执行。被占场景下有三种选择按推荐顺序1. 用钩子临时停掉占用进程。这是端口冲突 申请证书 最稳的做法钩子逻辑同样适用于自动续期certbot certonly --standalone -d example.com \ --pre-hook systemctl stop nginx \ --post-hook systemctl start nginx # pre-hook验证前停掉占用 80 的服务 # post-hook验证后自动拉起验证方式命令跑完后systemctl is-active nginx应输出active。2. 换监听端口--http-01-port 8080让 Certbot 监听 8080。注意换端口不等于改协议Lets Encrypt 仍从 80 抓取验证文件必须在防火墙上把外部 80 的流量转发到本机 8080否则验证必然失败。3. 指定网卡绑定多网卡机器用--http-01-address 192.168.1.100默认空值即绑定所有接口见certbot/src/certbot/_internal/constants.py。另外--http-01-port 0会随机挑一个空闲端口常配合--debug-challenges做本地调试——它会停在挑战提交前等你确认加-v还能打印完整的挑战 URL方便手动 curl 验证。到期前它自己做了什么Lets Encrypt 证书 90 天过期靠定时任务驱动续期certbot renew由 cron 或 systemd timer 周期性执行即可它只做幂等检查只对剩余有效期不足 30 天的证书重新签发其余跳过。注意certbot renew不会沿用你手动申请时的--standalone而是使用每张证书申请时记录的 authenticator 参数如果当时是 standalone 方式签的续期时同样会临时占用 80 端口需要时加--pre-hook/--post-hookcertbot renew --pre-hook systemctl stop nginx \ --post-hook systemctl start nginx首次接入生产前建议先打一张测试证书确认流程certbot certonly --standalone --test-cert -d test.example.com。--test-cert走 staging 环境等价于--server指向 staging签出的证书浏览器不信任但不会占用正式环境的速率配额。验证方式staging 证书同样落盘到/etc/letsencrypt/live/可用certbot certificates看到 Expiry Date。验证失败的排查路径场景一端口被占。报错原文Could not bind TCP port 80 because it is already in use by another process on this system (such as a web server). Please stop the program in question and then try again.定位三步sudo lsof -i :80找出占用进程 → 确认无其他程序在抢端口 →systemctl stop 服务后重跑。解决重跑同一条 certbot 命令或改用上一节的 pre-hook 方案。场景二CA 抓不到验证文件。报错原文The Certificate Authority failed to download the challenge files from the temporary standalone webserver started by Certbot on port 80. Ensure that the listed domains point to this machine and that it can accept inbound connections from the internet.这是证书流程失败不是端口问题——Certbot 本地监听成功了但外部连不进来。定位三步dig example.com short确认 A 记录指向本机公网 IP检查安全组/防火墙入站是否放行 TCP 80加--debug-challenges -v重跑复制打印出的挑战 URL 在本机外网环境 curl 一遍。解决修 DNS 或放行端口后重跑。场景三权限。报错原文含you dont have the appropriate permissions (for example, you arent running this program as root)用 root 或 sudo 重跑即可。所有申请过程的详细日志在/var/log/letsencrypt/letsencrypt.log上面三步的输出都在里面。边界与自查入口Standalone 适合无 Web 服务器或可短暂停服务的 http-01 单域名申请90 天有效期加certbot renew可做到免运维续期如果你的域名需要通配符或 80 端口完全无法腾出应转向 dns-01 认证Certbot 提供了一组 DNS 插件如 certbot-dns-route53、certbot-dns-cloudflare。自查入口certbot --help standalone查看当前版本的参数认证方式对比见certbot/docs/using.rst配置文件的写法示例见certbot/examples/cli.ini。【免费下载链接】certbotCertbot is EFFs tool to obtain certs from Lets Encrypt and (optionally) auto-enable HTTPS on your server. It can also act as a client for any other CA that uses the ACME protocol.项目地址: https://gitcode.com/gh_mirrors/ce/certbot创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考