乐云主机笔记

  • 首页
  • 学习记录
  • 资源下载
  • 新手教程
  • 其他
  • 脚本源码
  • 自用主机
  • 主机优惠
  • 域名优惠
  • 网赚项目

  1. 首页
  2. 学习记录
  3. 正文

通过 Let’s Encrypt 为 IP 地址签发免费 SSL 证书

2026年 1月 12日 345点热度 0人点赞 0条评论

终于 Let’s Encrypt 正式支持1为 IP 地址签发免费 SSL 证书了🎉今天以 acme.sh 为例跟大家分享如何自动申请 IP 地址证书。

Let’s Encrypt 默认只会签发普通域名证书,九十天过期。如果想签发 IP 证书,需要指定 ACME profile。这些 profile 可以简单理解为证书类型参数,可以在签发证书时指定。不过目前还有些 ACME 客户端不支持 profile 参数。好在 acme.sh 已经支持了2。

一、申请方法

我们先看看 Let’s Encrypt 支持哪些 profile

~# acme.sh --list-profiles --server letsencrypt
[Thu Dec 18 03:27:15 UTC 2025] Fetching profiles from LetsEncrypt.org (https://acme-v02.api.letsencrypt.org/directory)...

name            info
--------------------------------------------------------------------
classic         https://letsencrypt.org/docs/profiles#classic
shortlived      https://letsencrypt.org/docs/profiles#shortlived
tlsclient       https://letsencrypt.org/docs/profiles#tlsclient
tlsserver       https://letsencrypt.org/docs/profiles#tlsserver

一共有四种 profile,第一种 classic 就是我们一直在用九十天域名证书。第二种 shortlived 顾名思义就是短期证书。签发 IP 地址证书就需要用这种。

IP 地址证书有效期为7天,只能通过 HTTP-01 来验证控制权,也就是说你需要在 IP 地址对应的主机上监听 80 端口处理相关的 HTTP 请求。

好,现在给出签发命令:

wget https://raw.githubusercontent.com/acmesh-official/acme.sh/refs/heads/master/acme.sh
bash /root/acme.sh --issue --server letsencrypt \
    --cert-profile shortlived  --days 5 \
    -w /var/www/html \
    -d 192.9.228.95 \
    -d 2603:c024:c00c:9e00:1::

需要注意以下几点:

  • 通过 --cert-profile 参数指定 shortlived profile,只有这个 profile 才能签发 IP 证书
  • 通过 --days 参数指定证书更新时间,因为 IP 地址证书7天有效,更新时间需要小于7
  • 通过 -d 参数指定 IP 地址,同时支持 IPv4 和 IPv6 地址,一张证书内可以有多个地址

如果一切顺利,acme.sh 会输出以下结果:

[Thu Dec 18 03:10:14 UTC 2025] Using CA: https://acme-v02.api.letsencrypt.org/directory
[Thu Dec 18 03:10:14 UTC 2025] Creating domain key
[Thu Dec 18 03:10:14 UTC 2025] The domain key is here: /root/.acme.sh/192.9.228.95_ecc/192.9.228.95.key
[Thu Dec 18 03:10:14 UTC 2025] Multi domain='IP:192.9.228.95,IP:2603:c024:c00c:9e00:1::'
[Thu Dec 18 03:10:15 UTC 2025] Getting webroot for domain='192.9.228.95'
[Thu Dec 18 03:10:15 UTC 2025] Getting webroot for domain='2603:c024:c00c:9e00:1::'
[Thu Dec 18 03:10:15 UTC 2025] Verifying: 192.9.228.95
[Thu Dec 18 03:10:15 UTC 2025] Pending. The CA is processing your order, please wait. (1/30)
[Thu Dec 18 03:10:19 UTC 2025] Success
[Thu Dec 18 03:10:19 UTC 2025] Verifying: 2603:c024:c00c:9e00:1::
[Thu Dec 18 03:10:19 UTC 2025] Pending. The CA is processing your order, please wait. (1/30)
[Thu Dec 18 03:10:23 UTC 2025] Success
[Thu Dec 18 03:10:23 UTC 2025] Verification finished, beginning signing.
[Thu Dec 18 03:10:23 UTC 2025] Let's finalize the order.
[Thu Dec 18 03:10:23 UTC 2025] Le_OrderFinalize='https://acme-v02.api.letsencrypt.org/acme/finalize/1373445436/459962244086'
[Thu Dec 18 03:10:24 UTC 2025] Downloading cert.
[Thu Dec 18 03:10:24 UTC 2025] Le_LinkCert='https://acme-v02.api.letsencrypt.org/acme/cert/06115654d6ba3e23ef457b9702144ed8d4c7'
[Thu Dec 18 03:10:24 UTC 2025] Cert success.
-----BEGIN CERTIFICATE-----
MIIDWjCCAuGgAwIBAgISBhFWVNa6PiPvRXuXAhRO2NTHMAoGCCqGSM49BAMDMDIx
CzAJBgNVBAYTAlVTMRYwFAYDVQQKEw1MZXQncyBFbmNyeXB0MQswCQYDVQQDEwJF
ODAeFw0yNTEyMTgw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cert is in: /root/.acme.sh/192.9.228.95_ecc/192.9.228.95.cer

我们也可以查看当前已经签发的证书列表:

$ acme.sh --list
Main_Domain     KeyLength       SAN_Domains     Profile CA      Created Renew
192.9.228.95    "ec-256"        2603:c024:c00c:9e00:1:: shortlived      LetsEncrypt.org 2025-12-18T03:10:24Z    2026-02-15T03:10:24Z

这是我的第一张 IP 地址证书

https://crt.sh/?q=bdd2cbdc676e55925552fc39f05ba1b0457b13b7c4babca37f5ec74a8078c970

这是 IPv4 测试站 https://192.9.228.95/

这是 IPv6 测试站 https://[2603:c024:c00c:9e00:1::]/

在使用上,IP 证书跟域名证书几乎没有区别。这是我的 Nginx 配置:

server {
  listen 443 ssl default_server;
  listen [::]:443 ssl default_server;

  ssl_certificate /root/.acme.sh/192.9.228.95_ecc/fullchain.cer;
  ssl_certificate_key /root/.acme.sh/192.9.228.95_ecc/192.9.228.95.key;

  server_name 192.9.228.95;
  server_name 2603:c024:c00c:9e00:1::;

  root /var/www/html;

  location / {
    try_files $uri $uri/ @ruby =404;
  }
}

唯一需要注意的是 IP 地址网站需要设置为 default_server 不然访问时会展示默认网站内容。

最后说一下为什么要用 IP 地址证书。

一般 IP 地址很难记忆,而且有时候可能会被屏蔽,所以才有了域名。一方面域名容易记,另一方面,如果 IP 被封之后还可以换新的地址。所以,一直以来直接给 IP 地址签发 SSL 证书的应用场景并不多。因而 IP 地址证书几乎都需要付费才能获得。

但是,随着相关部门对网络管控越来越严格,基于 SNI 的屏蔽技术开始普及。也就是说,他们可以直接屏蔽域名🤦‍♂️这导致很多场景下只能使用临时域名或者直接使用 IP 地址。还有一种场景是 DoH,使用域名除了容易被封之外,另一个问题是会增大解析延迟,所以大部分服务都支持通过 IP 地址直接访问 HTTPS 服务。

二、使用cron或者计划任务自动续期

宝塔面板添加计划任务,每五天执行一次更新续期

bash /root/acme.sh --issue --force --server letsencrypt \
--cert-profile shortlived --days 5 \
-w /www/wwwroot/192.9.228.95 \
-d 192.9.228.95

三、反向代理时如何续期

该IP用于反向代理至HTTPS://b.b.b.b时如何续签

核心问题是:IP 建站并配置反向代理后,HTTP-01 验证方式(通过 /.well-known/ 路径验证)被反向代理拦截,导致 acme.sh 自动续签失败。

方案 :反向代理配置例外规则(推荐,改动最小)
核心思路:在反向代理配置中,为 /.well-known/acme-challenge/ 路径单独放行,不转发到后端,直接指向 acme.sh 验证文件的真实目录。这种方式无需改变验证方式,只需修改反向代理配置,是最简洁的方案。
以 Nginx 为例(主流反向代理)
假设你的反向代理配置文件在 /etc/nginx/conf.d/ip-proxy.conf,修改如下:

server {
listen 80;
server_name 192.9.228.95; # 你的IP

# 关键:ACME验证路径例外,优先匹配
location ^~ /.well-known/acme-challenge/ {
root /var/www/html; # 必须和你申请证书时的 -w 参数路径一致
try_files $uri =404;
# 可选:增加权限和缓存配置
default_type text/plain;
expires -1;
add_header Cache-Control "no-store, no-cache, must-revalidate";
}

# 其他路径反向代理到目标地址
location / {
proxy_pass https://b.b.b.b;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

# HTTPS 服务(如果已配置)
server {
listen 443 ssl;
server_name 192.9.228.95;

# SSL 证书路径(acme.sh 默认生成路径)
ssl_certificate /root/.acme.sh/192.9.228.95/fullchain.cer;
ssl_certificate_key /root/.acme.sh/192.9.228.95/192.9.228.95.key;

# 同样添加 ACME 验证例外(防止 HTTPS 端口也被代理拦截)
location ^~ /.well-known/acme-challenge/ {
root /var/www/html;
try_files $uri =404;
default_type text/plain;
expires -1;
}

location / {
proxy_pass https://b.b.b.b;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

配置生效步骤

检查 Nginx 配置语法:nginx -t
重新加载配置:systemctl reload nginx
测试续签:acme.sh --renew -d 192.9.228.95 --server letsencrypt

标签: 暂无
最后更新:2026年 3月 9日

wangzhe12588

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >
搜一搜
文章目录
  • 一、申请方法
  • 二、使用cron或者计划任务自动续期
  • 三、反向代理时如何续期

归档

  • 2026 年 4 月
  • 2026 年 3 月
  • 2026 年 1 月
  • 2025 年 12 月
  • 2025 年 11 月
  • 2025 年 10 月
  • 2025 年 9 月
  • 2025 年 8 月
  • 2025 年 7 月
  • 2025 年 6 月
  • 2025 年 5 月
  • 2025 年 4 月
  • 2025 年 3 月
  • 2025 年 2 月
  • 2025 年 1 月
  • 2024 年 12 月
  • 2024 年 11 月
  • 2024 年 10 月
  • 2024 年 9 月
  • 2024 年 7 月
  • 2024 年 3 月
  • 2024 年 2 月
  • 2024 年 1 月
  • 2023 年 12 月
  • 2023 年 11 月
  • 2023 年 10 月
  • 2023 年 9 月
  • 2023 年 8 月
  • 2023 年 7 月
  • 2023 年 6 月
  • 2023 年 5 月
  • 2023 年 4 月
  • 2023 年 3 月
  • 2023 年 2 月
  • 2023 年 1 月
  • 2022 年 12 月
  • 2022 年 11 月
  • 2022 年 10 月
  • 2022 年 9 月
  • 2022 年 8 月
  • 2022 年 7 月
  • 2022 年 6 月
  • 2022 年 5 月
  • 2022 年 4 月
  • 2022 年 3 月
  • 2022 年 2 月
  • 2022 年 1 月
  • 2021 年 12 月
  • 2021 年 11 月
  • 2021 年 10 月
  • 2021 年 9 月
  • 2021 年 8 月
  • 2021 年 7 月
  • 2021 年 6 月
  • 2021 年 5 月
  • 2021 年 4 月
  • 2021 年 3 月
  • 2021 年 2 月
  • 2021 年 1 月
  • 2020 年 12 月
  • 2020 年 11 月
  • 2020 年 10 月
  • 2020 年 9 月
  • 2020 年 8 月
  • 2020 年 7 月
  • 2020 年 6 月
  • 2020 年 5 月
  • 2020 年 4 月
  • 2020 年 3 月
  • 2020 年 2 月
  • 2020 年 1 月
  • 2019 年 12 月
  • 2019 年 11 月
  • 2019 年 10 月
  • 2019 年 9 月
  • 2019 年 8 月
  • 2019 年 7 月
  • 2019 年 6 月
  • 2019 年 5 月
  • 2019 年 4 月
  • 2019 年 3 月
  • 2019 年 2 月
  • 2019 年 1 月
  • 2018 年 12 月
  • 2018 年 11 月
  • 2018 年 10 月
  • 2018 年 9 月
  • 2018 年 8 月
  • 2018 年 7 月
  • 2018 年 6 月
  • 2018 年 5 月
  • 2018 年 4 月
  • 2018 年 3 月
  • 2018 年 2 月
  • 2017 年 12 月
  • 2017 年 11 月
  • 2017 年 10 月
  • 2017 年 9 月
  • 2017 年 8 月
  • 2017 年 7 月

分类

  • 主机优惠
  • 其他
  • 域名优惠
  • 学习记录
  • 新手教程
  • 网赚项目
  • 脚本源码
  • 自用主机
  • 资源下载

COPYRIGHT © 2021 Letcloud.cn. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

粤ICP备15031609号-3

粤公网安备44050702001530号