Let's Encrypt 公网 IP 证书签发实操指南
frigidpluto Views: ...
2025 年 12 月,Let’s Encrypt 宣布正式支持为 IP 地址签发 SSL 证书,这为直接使用 IP 地址提供 HTTPS 服务的场景带来了便利。下面将详细介绍实现方法。
准备工作
在开始前请确保:
- 拥有公网 IP 地址(不支持内网 IP)
- 80/443 端口可访问
- 系统环境为 Linux(Windows 用户可通过 WSL 实现)
安装与配置 acme.sh
acme.sh 是目前最流行的自动化证书管理工具,支持 Let’s Encrypt 等多种 CA 机构:
curl https://get.acme.sh | sh -s [email protected]
已安装的用户可以通过 ./acme.sh upgrade 命令升级到最新版本。
证书签发方式
1. 独立模式(Standalone)
适用于没有运行 Web 服务的环境,acme.sh 会临时启动一个 Web 服务器进行验证:
./acme.sh --issue --server letsencrypt -d 1.2.3.4 \
--certificate-profile shortlived --days 3 --standalone
参数说明:
--issue:申请新证书。--server letsencrypt:使用 Let’s Encrypt 服务器。-d 1.2.3.4:证书申请的目标是 IP 地址 1.2.3.4--certificate-profile shortlived:申请一个短期证书--days 3:设置 3 天有效期(测试最长可设置 90 天)--standalone:使用独立验证模式,不依赖现有的 Web 服务器。(需要80/443端口)
2. Web 服务器模式
适用于已有 Web 服务(如 Nginx)的环境,不会中断现有服务。首先配置 Nginx:
server {
listen 80 default_server;
server_name _;
location ~ ^/.well-known/(acme-challenge|pki-validation)/ {
add_header Content-Type text/plain;
root /wwwroot/letsencrypt;
}
}
然后运行签发命令:
./acme.sh --issue --server letsencrypt -d 1.2.3.4 \
-w /wwwroot/letsencrypt --certificate-profile shortlived --days 8
证书使用
生成的证书默认存储在 /root/.acme.sh/1.2.3.4_ecc/ 目录,主要包含:
1.2.3.4.key:私钥文件fullchain.cer:完整证书链
在 Nginx 中的配置示例:
ssl_certificate /root/.acme.sh/1.2.3.4_ecc/fullchain.cer;
ssl_certificate_key /root/.acme.sh/1.2.3.4_ecc/1.2.3.4.key;
自动化续期
由于短期证书有效期短,建议设置定时任务自动续期:
0 0 * * * /root/.acme.sh/acme.sh --cron --home /root/.acme.sh > /dev/null
对于 Docker 环境的应用,续期后还需重启服务:
51 1 */10 * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" \
--reloadcmd "docker exec appinn-nginx-1 nginx -s reload"
应用场景
虽然 IP 证书在大部分场景下不如域名证书实用,但在以下情况可能发挥作用:
- 临时测试环境
- 无域名备案要求的内部系统
- 特殊网络架构下的服务访问


