侯体宗的博客
  • 首页
  • Hyperf版
  • beego仿版
  • 人生(杂谈)
  • 技术
  • 关于我
  • 更多分类
    • 文件下载
    • 文字修仙
    • 中国象棋ai
    • 群聊
    • 九宫格抽奖
    • 拼图
    • 消消乐
    • 相册

如何给自己的网站域名生成永久的免费证书,acme.sh开源项目了解一下

技术  /  管理员 发布于 3年前   1271

现在很多地方都有免费证书,但是基本上都有期限,

比如:

阿里云免费证书就是固定1年,然后失效,

虽然重新生成步骤简单,但也不是一个成熟程序员该做的事


git:

https://github.com/acmesh-official/acme.sh
https://github.com/acmesh-official/acme.sh/wiki/%E8%AF%B4%E6%98%8E

acme.sh 实现了 acme 协议, 可以从 Let's Encrypt、ZoreSSL、buypass、sslcom 生成免费的证书。


进入步骤:


1.安装 acme.sh

以下三种任选一种即可,把 [email protected] 修改成自己的邮箱。

安装过程不会污染任何功能和文件,所有的修改都限制在安装目录中:

~/.acme.sh/

a.通过 https://get.acme.sh 安装

curl https://get.acme.sh | sh -s [email protected]

或者

wget -O - https://get.acme.sh | sh -s [email protected]

b.通过 GitHub 安装

curl https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh | sh -s -- --install-online -m [email protected]

或者

wget -O - https://raw.githubusercontent.com/acmesh-official/acme.sh/master/acme.sh | sh -s -- --install-online -m [email protected]

c.通过 git clone 安装

# 使用加速通道

git clone https://github.com.cnpmjs.org/acmesh-official/acme.sh.git
cd acme.sh
./acme.sh --install -m [email protected]


安装过程进行了以下几步:

(1)acme.sh 安装到 home 目录下

~/.acme.sh/

(2)创建一个 bash 的 alias

alias acme.sh=~/.acme.sh/acme.sh

(3)创建 cronjob,每天 0:00 自动检测所有证书,如果快过期了,会自动更新证书。


2.生成证书

以下两种任选一种即可,把 mydomain.com 更换成自己的域名。

如何生成泛域名证书,请参阅 使用 acme.sh 生成免费的泛域名证书


(1)http 方式

指定域名,并指定网站根目录。 acme.sh 会全自动生成验证文件,并放到网站的根目录,自动完成验证。最后会删除验证文件,整个过程没有任何副作用。

acme.sh --issue -d mydomain.com -d www.mydomain.com --webroot /home/wwwroot/mydomain.com/

如果使用 apache 服务器, acme.sh 可以智能的从 apache 的配置中自动完成验证,不需要指定网站根目录:

acme.sh --issue -d mydomain.com --apache

如果使用 nginx 服务器,或者反向代理,acme.sh 可以智能的从 nginx 的配置中自动完成验证,不需要指定网站根目录:

acme.sh --issue -d mydomain.com --nginx

注意!

无论是 apache 还是 nginx 模式,acme.sh 不会自动修改配置文件,需要手动修改配置文件,否则无法访问 https

如果还没有运行任何 web 服务,80 端口是空闲的,那么 acme.sh 还能假装自己是一个 webserver,临时监听 80 端口,完成验证:

acme.sh --issue -d mydomain.com --standalone


(2)DNS 方式

好处:

不需要任何服务器, 不需要任何公网 IP, 只需要 DNS 的解析记录即可完成验证。

坏处:

如果不同时配置 Automatic DNS API 则 acme.sh 将无法自动更新证书。

acme.sh --issue --dns -d mydomain.com \
 --yes-I-know-dns-manual-mode-enough-go-ahead-please

acme.sh 会生成相应的解析记录,到域名解析中添加 TXT 记录,解析成功后,重新生成证书。

acme.sh --renew -d mydomain.com \
  --yes-I-know-dns-manual-mode-enough-go-ahead-please

DNS 方式的真正强大之处在于可以使用域名解析商提供的 api 自动添加 TXT 记录完成验证。

acme.sh 目前支持几十种域名服务商:

https://github.com/acmesh-official/acme.sh/wiki/dnsapi

以 dnspod 为例, 需要先登录到 dnspod 账号, 生成 api id 和 api key

export DP_Id="1234"
export DP_Key="qwertyuiopasdfghjkl"
acme.sh --issue --dns dns_dp -d mydomain.com -d www.mydomain.com

acme.sh 会自动生成证书,并且会记录 api id 和 api key 以后再使用 dnspod api 时就不需要再指定了。


3.复制/安装 证书

注意!默认生成的证书都放在安装目录下:

~/.acme.sh/,不要直接使用此目录下的文件,这里面的文件都是内部使用, 而且目录结构可能会变化。

正确的使用方法是使用 --install-cert 命令,指定目标位置,证书文件会被复制到相应的位置。

Apache
acme.sh --install-cert -d example.com \
--cert-file      /path/to/certfile/in/apache/cert.pem  \
--key-file       /path/to/keyfile/in/apache/key.pem  \
--fullchain-file /path/to/fullchain/certfile/apache/fullchain.pem \
--reloadcmd     "service apache2 force-reload"
Nginx
acme.sh --install-cert -d example.com \
--key-file       /path/to/keyfile/in/nginx/key.pem  \
--fullchain-file /path/to/fullchain/nginx/cert.pem \
--reloadcmd     "service nginx force-reload"


4.更新证书

证书在 60 天以后会自动更新,无需任何操作。


5.更新 acme.sh

升级 acme.sh 到最新版

acme.sh --upgrade

如果不想手动升级,也可以开启自动升级

acme.sh  --upgrade  --auto-upgrade

关闭自动更新

acme.sh --upgrade  --auto-upgrade  0


6.出错怎么办

在命令后添加 --debug 或 --debug 2 比如:

acme.sh --issue -d mydomain.com --nginx --debug 

或

acme.sh --issue -d mydomain.com --nginx --debug 2

或者查阅日志

~/.acme.sh/acme.sh.log

完


  • 上一条:
    windows系统中创建定时任务自动推送项目代码至码云、GitHub
    下一条:
    给主域名及二级域名统一证书,使用acme.sh生成免费泛域名证书
  • 昵称:

    邮箱:

    0条评论 (评论内容有缓存机制,请悉知!)
    最新最热
    • 分类目录
    • 人生(杂谈)
    • 技术
    • linux
    • Java
    • php
    • 框架(架构)
    • 前端
    • ThinkPHP
    • 数据库
    • 微信(小程序)
    • Laravel
    • Redis
    • Docker
    • Go
    • swoole
    • Windows
    • Python
    • 苹果(mac/ios)
    • 相关文章
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 2024.07.09日OpenAI将终止对中国等国家和地区API服务(0个评论)
    • 2024/6/9最新免费公益节点SSR/V2ray/Shadowrocket/Clash节点分享|科学上网|免费梯子(1个评论)
    • 国外服务器实现api.openai.com反代nginx配置(0个评论)
    • 2024/4/28最新免费公益节点SSR/V2ray/Shadowrocket/Clash节点分享|科学上网|免费梯子(1个评论)
    • 近期文章
    • 在go+gin中使用"github.com/skip2/go-qrcode"实现url转二维码功能(0个评论)
    • 在go语言中使用api.geonames.org接口实现根据国际邮政编码获取地址信息功能(1个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf分页文件功能(0个评论)
    • gmail发邮件报错:534 5.7.9 Application-specific password required...解决方案(0个评论)
    • 欧盟关于强迫劳动的规定的官方举报渠道及官方举报网站(0个评论)
    • 在go语言中使用github.com/signintech/gopdf实现生成pdf文件功能(0个评论)
    • Laravel从Accel获得5700万美元A轮融资(0个评论)
    • 在go + gin中gorm实现指定搜索/区间搜索分页列表功能接口实例(0个评论)
    • 在go语言中实现IP/CIDR的ip和netmask互转及IP段形式互转及ip是否存在IP/CIDR(0个评论)
    • PHP 8.4 Alpha 1现已发布!(0个评论)
    • 近期评论
    • 122 在

      学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..
    • 123 在

      Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..
    • 原梓番博客 在

      在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..
    • 博主 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..
    • 1111 在

      佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
    • 2016-10
    • 2016-11
    • 2017-07
    • 2017-08
    • 2017-09
    • 2018-01
    • 2018-07
    • 2018-08
    • 2018-09
    • 2018-12
    • 2019-01
    • 2019-02
    • 2019-03
    • 2019-04
    • 2019-05
    • 2019-06
    • 2019-07
    • 2019-08
    • 2019-09
    • 2019-10
    • 2019-11
    • 2019-12
    • 2020-01
    • 2020-03
    • 2020-04
    • 2020-05
    • 2020-06
    • 2020-07
    • 2020-08
    • 2020-09
    • 2020-10
    • 2020-11
    • 2021-04
    • 2021-05
    • 2021-06
    • 2021-07
    • 2021-08
    • 2021-09
    • 2021-10
    • 2021-12
    • 2022-01
    • 2022-02
    • 2022-03
    • 2022-04
    • 2022-05
    • 2022-06
    • 2022-07
    • 2022-08
    • 2022-09
    • 2022-10
    • 2022-11
    • 2022-12
    • 2023-01
    • 2023-02
    • 2023-03
    • 2023-04
    • 2023-05
    • 2023-06
    • 2023-07
    • 2023-08
    • 2023-09
    • 2023-10
    • 2023-12
    • 2024-02
    • 2024-04
    • 2024-05
    • 2024-06
    • 2025-02
    Top

    Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号 PHP交流群

    侯体宗的博客