
如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
结合Nginx与LuaJIT的高性能Web平台,用于动态、可编程的请求处理。

bash# 从GitHub Container Registry拉取 docker pull ghcr.io/oorabona/openresty:latest # 从Docker Hub拉取 docker pull oorabona/openresty:latest # 使用自定义配置运行 docker run -d \ --name openresty \ -p 80:80 \ -p 443:443 \ -v ./conf.d:/usr/local/openresty/nginx/conf/conf.d:ro \ -v ./lua:/usr/local/openresty/lualib/app:ro \ ghcr.io/oorabona/openresty:latest
yamlservices: openresty: image: ghcr.io/oorabona/openresty:latest ports: - "80:80" - "443:443" volumes: - ./conf.d:/usr/local/openresty/nginx/conf/conf.d:ro - ./lua:/usr/local/openresty/lualib/app:ro 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
在conf.d/目录中放置Nginx配置:
nginx# conf.d/default.conf server { listen 80; server_name localhost; location / { content_by_lua_block { ngx.say("Hello from OpenResty + Lua!") } } location /api { access_by_lua_file /usr/local/openresty/lualib/app/auth.lua; proxy_pass http://backend; } }
在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 http://backend; 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 http://origin; } }
lua-- lua/balancer.lua local balancer = require "ngx.balancer" 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 = balancer.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 #
以下是 oorabona/openresty 相关的常用 Docker 镜像,适用于 不同场景 等不同场景:
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务