acmev2怎么用_lua-resty-acme: ACMEv2 客户端和 Let's Encrypt 证书的自动化管理

相比于现有实现,不需要安装任何第三方程序或者 C 扩展,所有依赖均为 Lua 和 FFI 实现。

安装

使用 opm:

opm install fffonion/lua-resty-acme

opm 中没有 luaossl 库,所以这种安装使用的是基于 FFI 的 Openssl 后端;需要 OpenResty 链接了大于等于 1.1 版本的 OpenSSL。

如果有完整的编译工具链,可以使用 luarocks 安装,需要安装 OpenSSL 的头文件:

luarocks install lua-resty-acme

使用

以 /etc/openresty 目录为例,如果目录不存在,请自行修改。

生成一个账户密钥

openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -out /etc/openresty/account.key

生成一个默认证书

openssl req -newkey rsa:2048 -nodes -keyout /etc/openresty/default.pem -x509 -days 365 -out /etc/openresty/default.key

在 Nginx 配置的 http 节插入以下内容

resolver 8.8.8.8;

lua_shared_dict acme 16m;

lua_shared_dict autossl_events 128k;

init_by_lua_block {

require("resty.acme.autossl").init({

-- setting the following to true

-- implies that you read and accepted https://letsencrypt.org/repository/

tos_accepted = true,

-- uncomment following for first time setup

-- staging = true,

-- uncomment folloing to enable RSA + ECC double cert

-- domain_key_types = { 'rsa', 'ecc' },

account_key_path = "/etc/openresty/account.key",

account_email = "此处填写邮箱",

})

}

init_worker_by_lua_block {

require("resty.acme.autossl").init_worker()

}

# required to verify Let's Encrypt API

lua_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;

lua_ssl_verify_depth 2;

CentOS/Fedora 等系统的根证书在 /etc/ssl/certs/ca-bundle.crt ,请根据实际情况修改 lua_ssl_trusted_certificate。

首次配置时,建议将 init_by_lua_block 中的 staing = true 取消注释,以防错误过多触发限流;测试通过后再加回注释使用生产 API。

在需要使用证书的 server 节插入

server {

server_name example.com;

# fallback certs, make sure to create them before hand

ssl_certificate /etc/openresty/default.pem;

ssl_certificate_key /etc/openresty/default.key;

ssl_certificate_by_lua_block {

require("resty.acme.autossl").ssl_certificate()

}

location /.well-known {

content_by_lua_block {

require("resty.acme.autossl").serve_http_challenge()

}

}

}

配置完成后,reload nginx。

福利:

# RSA

echo q |openssl s_client -connect 随机子域名.acme.yooooo.us -port 8443 -cipher ECDHE-RSA-AES128-GCM-SHA256|openssl x509 -noout -text|grep -P "Public Key Algorithm|After"

# ECC

echo q |openssl s_client -connect 随机子域名.acme.yooooo.us -port 8443 -cipher ECDHE-ECDSA-AES128-GCM-SHA256|openssl x509 -noout -text|grep -P "Public Key Algorithm|After"

首次请求后等 10 秒钟,即可收到新证书加密的链接

欢迎讨论和提供建议!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值