
oorabona/openresty结合Nginx与LuaJIT的高性能Web平台,用于动态、可编程的请求处理。
 } } location /api { access_by_lua_file /usr/local/openresty/lualib/app/auth.lua; proxy_pass [***] } }
在lua/目录中创建Lua模块:
lua-- lua/auth.lua local jwt = require "resty.jwt" local token = ngx.var.http_authorization if not token then ngx.status = 401 ngx.say("缺少Authorization头") return ngx.exit(401) end -- 验证JWT令牌 local jwt_obj = jwt:verify("secret-key", token) if not jwt_obj.verified then ngx.status = 403 ngx.say("无效的令牌") return ngx.exit(403) end
bash# 使用LuaRocks安装包 docker exec openresty luarocks install lua-resty-jwt # 列出已安装包 docker exec openresty luarocks list
| 参数 | 描述 | 默认值 |
|---|---|---|
VERSION | OpenResty版本 | latest |
RESTY_IMAGE_BASE | 基础镜像名称 | alpine |
RESTY_IMAGE_TAG | 基础镜像标签 | latest |
RESTY_VERSION | OpenResty版本(与VERSION相同) | ${VERSION} |
RESTY_OPENSSL_VERSION | OpenSSL版本(固定为1.1.1) | 1.1.1w |
RESTY_OPENSSL_PATCH_VERSION | OpenSSL补丁版本 | 1.1.1f |
RESTY_PCRE_VERSION | PCRE版本(固定为8.x) | 8.45 |
RESTY_J | 并行构建任务数 | 4 |
RESTY_CONFIG_OPTIONS | Nginx构建选项 | (参见Dockerfile) |
RESTY_CONFIG_OPTIONS_MORE | 额外配置选项 | -j${RESTY_J} |
RESTY_LUAJIT_OPTIONS | LuaJIT编译选项 | (参见Dockerfile) |
RESTY_ADD_PACKAGE_BUILDDEPS | 额外构建依赖 | |
RESTY_ADD_PACKAGE_RUNDEPS | 额外运行时依赖 | |
RESTY_EVAL_PRE_CONFIGURE | 配置前执行命令 | |
RESTY_EVAL_POST_MAKE | 编译后执行命令 | |
LUAROCKS_VERSION | LuaRocks版本 | 3.13.0 |
ENABLE_HTTP_PROXY_CONNECT | 启用代理连接模块 | false |
NGX_PROXY_CONNECT_VERSION | 代理连接模块版本 | 0.0.7 |
| 变量 | 描述 | 默认值 |
|---|---|---|
PATH | 包含OpenResty二进制文件路径 | /usr/local/openresty/... |
OpenResty使用标准Nginx环境变量:
envsubst处理动态变量| 路径 | 描述 |
|---|---|
/usr/local/openresty/nginx/conf/conf.d | Nginx配置文件(建议只读挂载) |
/usr/local/openresty/lualib/app | 自定义Lua模块(建议只读挂载) |
/var/run/openresty | 运行时文件(建议使用tmpfs) |
/var/cache/nginx | 缓存目录(建议使用tmpfs) |
/var/log/nginx | 日志文件(默认输出到stdout/stderr) |
| 端口 | 协议 | 描述 |
|---|---|---|
| 80 | HTTP | 默认HTTP端口 |
| 443 | HTTPS | 默认HTTPS端口 |
可在Nginx配置中自定义端口。如需非特权运行,使用>1024的端口。
nginx运行(uid 101,gid 101)/sbin/nologin shell以下docker-compose.yml示例展示安全最佳实践:
yamlservices: openresty: image: ghcr.io/oorabona/openresty:latest read_only: true # 只读文件系统 tmpfs: - /var/run/openresty # 可写运行时目录 - /var/cache/nginx # 可写缓存目录 - /tmp # 可写临时目录 cap_drop: - ALL # 移除所有能力 cap_add: - NET_BIND_SERVICE # 仅允许绑定特权端口 security_opt: - no-new-privileges:true # 防止权限提升
如需完全无root运行:
yamlservices: openresty: image: ghcr.io/oorabona/openresty:latest user: "101:101" # 以nginx:nginx用户运行 read_only: true tmpfs: - /var/run/openresty - /var/cache/nginx - /tmp cap_drop: - ALL security_opt: - no-new-privileges:true ports: - "8080:8080" - "8443:8443"
注意:需将Nginx配置修改为监听8080/8443而非80/443。
内置健康检查验证OpenResty响应状态:
dockerfileHEALTHCHECK --interval=30s --timeout=10s --start-period=30s --retries=3 \ CMD curl -f http://localhost/nginx_status || exit 1
确保Nginx配置包含状态端点:
nginxlocation /nginx_status { stub_status on; access_log off; allow 127.0.0.1; deny all; }
容器包含以下固定依赖:
| 依赖项 | 版本 | 监控状态 | 说明 |
|---|---|---|---|
| Alpine Linux | latest | 活跃 | 基础镜像 |
| OpenResty | (来自version.sh) | 活跃 | 主应用 |
| OpenSSL | 1.1.1w | 已冻结(EOL) | OpenSSL 1.1.1系列已于2023-09-11结束支持 |
| PCRE | 8.45 | 已冻结(EOL) | PCRE 8.x为 legacy 版本,未使用PCRE2 |
| LuaRocks | 3.13.0 | 活跃 | Lua包管理器 |
| ngx_http_proxy_connect_module | 0.0.7 | 活跃 | 可选正向代理支持 |
关于冻结依赖的说明:
这些冻结版本通过OpenResty的补丁机制接收安全更新。
核心HTTP模块:
动态模块:
流模块:
邮件模块:
/usr/local/openresty/ ├── bin/ │ ├── openresty # OpenResty二进制文件 │ ├── resty # Resty命令行工具 │ └── restydoc # 文档查看器 ├── luajit/ │ └── bin/ │ ├── luajit # LuaJIT解释器 │ └── luarocks # Lua包管理器 ├── lualib/ # Lua库 │ ├── resty/ # OpenResty Lua模块 │ └── app/ # 自定义模块(挂载点) ├── nginx/ │ ├── conf/ │ │ ├── nginx.conf # 主配置文件 │ │ └── conf.d/ # 额外配置(挂载点) │ ├── html/ # 默认网站根目录 │ └── logs/ # 日志(符号链接到stdout/stderr) ├── openssl/ # OpenSSL库 └── pcre/ # PCRE库
nginxupstream backend { server api1:3000; server api2:3000; keepalive 32; } server { listen 80; location /api/v1 { access_by_lua_block { -- 限流 local limit = require "resty.limit.req" local lim = limit.new("limit_store", 100, 50) local key = ngx.var.remote_addr local delay, err = lim:incoming(key, true) if not delay then if err == "rejected" then return ngx.exit(429) end end } proxy_pass [***] proxy_http_version 1.1; proxy_set_header Connection ""; } }
lua-- lua/waf.lua local rules = { sql_injection = [[(\%27)|(\')|(\-\-)|(\%23)|(#)]], xss = [[(\%3C)|(<)|(\%3E)|(>)|(\%3c)|(\%3e)]], } local uri = ngx.var.uri local args = ngx.var.args or "" for rule_name, pattern in pairs(rules) do if string.match(uri, pattern) or string.match(args, pattern) then ngx.log(ngx.ERR, "WAF: 阻止", rule_name, "***尝试") return ngx.exit(403) end end
nginxproxy_cache_path /var/cache/nginx levels=1:2 keys_zone=cache:10m max_size=1g inactive=60m; server { listen 80; location / { proxy_cache cache; proxy_cache_valid 200 60m; proxy_cache_valid 404 1m; proxy_cache_key "$scheme$request_method$host$request_uri"; proxy_cache_bypass $http_cache_control; add_header X-Cache-Status $upstream_cache_status; proxy_pass [***] } }
lua-- lua/***.lua local *** = require "ngx.***" local redis = require "resty.redis" -- 从Redis获取健康后端 local red = redis:new() red:connect("redis", 6379) local backends = red:smembers("healthy_backends") -- 轮询选择 local current = ngx.shared.balance:incr("counter", 1, 0) local index = (current % #backends) + 1 local backend = backends[index] -- 设置上游服务器 local ok, err = ***.set_current_peer(backend) if not ok then ngx.log(ngx.ERR, "设置后端失败: ", err) return ngx.exit(500) end
lua_shared_dict在工作进程间缓存数据-jdump分析热点代码bash# 检查当前版本 ./version.sh #




探索更多轩辕镜像的使用方法,找到最适合您系统的配置方式
通过 Docker 登录认证访问私有仓库
无需登录使用专属域名
Kubernetes 集群配置 Containerd
K3s 轻量级 Kubernetes 镜像加速
VS Code Dev Containers 配置
Podman 容器引擎配置
HPC 科学计算容器配置
ghcr、Quay、nvcr 等镜像仓库
Harbor Proxy Repository 对接专属域名
Portainer Registries 加速拉取
Nexus3 Docker Proxy 内网缓存
需要其他帮助?请查看我们的 常见问题Docker 镜像访问常见问题解答 或 提交工单
manifest unknown
no matching manifest(架构)
TLS 证书失败
DNS 超时
410 Gone 排查
402 与流量用尽
401 认证失败
429 限流
D-Bus 凭证提示
413 与超大单层
来自真实用户的反馈,见证轩辕镜像的优质服务