lua-resty-auto-ssl 配置详解:从基础设置到高级选项
lua-resty-auto-ssl 配置详解:从基础设置到高级选项
【免费下载链接】lua-resty-auto-sslOn the fly (and free) SSL registration and renewal inside OpenResty/nginx with Let's Encrypt.项目地址: https://gitcode.com/gh_mirrors/lu/lua-resty-auto-ssl
什么是 lua-resty-auto-ssl?
lua-resty-auto-ssl 是一个为 OpenResty/nginx 设计的免费 SSL 证书自动注册与续期工具,通过 Let's Encrypt 实现证书的动态管理。它能够在请求过程中自动处理 SSL 证书的申请、更新和配置,让开发者无需手动管理证书生命周期,极大简化了 HTTPS 部署流程。
基础配置指南
环境准备
使用以下命令克隆项目仓库:
git clone https://gitcode.com/gh_mirrors/lu/lua-resty-auto-ssl核心模块引入
在 nginx.conf 中添加必要的 Lua 模块引用:
lua_shared_dict auto_ssl 1m; lua_shared_dict auto_ssl_settings 64k; init_by_lua_block { auto_ssl = (require "resty.auto-ssl").new() auto_ssl:set("allow_domain", function(domain) return true end) auto_ssl:init() }证书存储配置
默认使用文件系统存储证书,配置路径位于 lib/resty/auto-ssl/storage_adapters/file.lua。如需修改存储位置,可通过以下方式设置:
auto_ssl:set("storage_adapter", "file") auto_ssl:set("storage_config", { dir = "/path/to/certificates" })高级功能配置
Redis 存储适配器
对于分布式环境,推荐使用 Redis 存储证书,配置文件位于 lib/resty/auto-ssl/storage_adapters/redis.lua:
auto_ssl:set("storage_adapter", "redis") auto_ssl:set("storage_config", { host = "127.0.0.1", port = 6379, db = 0, password = "your_redis_password" })Let's Encrypt 配置
证书提供商设置位于 lib/resty/auto-ssl/ssl_providers/lets_encrypt.lua,可配置 ACME 端点和申请参数:
auto_ssl:set("ssl_provider", "lets_encrypt") auto_ssl:set("lets_encrypt_production", true) -- 生产环境切换 auto_ssl:set("lets_encrypt_agreement", "https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf")自动续期设置
证书续期逻辑在 lib/resty/auto-ssl/jobs/renewal.lua 中实现,默认会在证书过期前 30 天自动触发续期。可通过以下参数调整:
auto_ssl:set("renew_check_interval", 86400) -- 每日检查 auto_ssl:set("renew_threshold", 2592000) -- 30天阈值实用工具模块
辅助功能集
项目提供多个实用工具位于 lib/resty/auto-ssl/utils/ 目录,包括:
- 证书检查:has_certificate.lua
- 时间解析:parse_openssl_time.lua
- 随机数生成:random_seed.lua
配置示例
完整的 Nginx 配置示例可参考测试目录下的 spec/config/nginx.conf.etlua,包含了基本设置和高级功能的典型配置。
常见问题解决
权限问题
确保 Nginx 进程对证书存储目录有读写权限,可参考 spec/worker_file_permissions_spec.lua 中的测试用例获取权限配置建议。
多 worker 配置
在多 worker 环境下,需确保共享存储配置正确,具体可参考 spec/multiple_workers_spec.lua 中的实现方案。
调试与日志
可通过配置日志级别和路径进行问题排查:
auto_ssl:set("log_level", ngx.INFO) auto_ssl:set("log_dir", "/var/log/auto-ssl")总结
lua-resty-auto-ssl 提供了从基础到高级的完整 SSL 证书自动化解决方案,通过灵活的配置选项和模块化设计,满足不同场景下的 HTTPS 部署需求。无论是简单的单服务器配置还是复杂的分布式环境,都能通过调整存储适配器、证书提供商和续期策略实现高效稳定的证书管理。
通过本文介绍的配置方法,您可以快速搭建起自动 SSL 证书管理系统,让网站安全部署变得简单高效。如需进一步了解项目细节,可查阅项目源代码和测试用例获取更多实现细节和最佳实践。
【免费下载链接】lua-resty-auto-sslOn the fly (and free) SSL registration and renewal inside OpenResty/nginx with Let's Encrypt.项目地址: https://gitcode.com/gh_mirrors/lu/lua-resty-auto-ssl
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
