面向生产、测试和多节点排障场景的 NGINX / OpenResty Docker 镜像。当前维护两条清晰的镜像线:
| 镜像线 | 推荐场景 | 当前标签 |
|---|---|---|
| 纯 NGINX Alpine / Ubuntu / CentOS | 轻量 Web、反向代理、四层转发、基础网关 | benyoo/nginx:alpine-1.31.1 |
| OpenResty Ubuntu | Lua、GeoIP、JWT/OIDC、动态访问策略 | benyoo/openresty:ubuntu-1.31.1.1 |
所有当前发布标签均支持 linux/amd64 和 linux/arm64,并内置 HTTP/3、HTTP/2、TLS、Stream、状态检测 vhost、健康检查、配置热加载、日志轮转、计划任务和默认首页诊断码。
| 镜像 | 基础镜像 | 版本 | OpenSSL | 架构 | 说明 |
|---|---|---|---|---|---|
benyoo/nginx:alpine-1.31.1 | benyoo/alpine:3.24.20260612 | NGINX 1.31.1 | 3.5.7 | amd64 / arm64 | 默认推荐,轻量快速 |
benyoo/nginx:ubuntu-1.31.1 | ubuntu:24.04 | NGINX 1.31.1 | 3.5.6 | amd64 / arm64 | 通用 Linux 运行环境 |
benyoo/nginx:centos-1.31.1 | benyoo/centos:9-stream-20260613 | NGINX 1.31.1 | 3.5.6 | amd64 / arm64 | EL 系生态和企业兼容 |
benyoo/openresty:ubuntu-1.31.1.1 | ubuntu:24.04 | OpenResty 1.31.1.1 | 随 OpenResty 构建 | amd64 / arm64 | Lua / OpenResty 能力 |
拉取镜像:
docker pull benyoo/nginx:alpine-1.31.1
docker pull benyoo/nginx:ubuntu-1.31.1
docker pull benyoo/nginx:centos-1.31.1
docker pull benyoo/openresty:ubuntu-1.31.1.1
| 能力 | NGINX Alpine | NGINX Ubuntu | NGINX CentOS | OpenResty Ubuntu |
|---|---|---|---|---|
linux/amd64 / linux/arm64 | ✅ | ✅ | ✅ | ✅ |
| HTTP/3 / QUIC 编译支持 | ✅ | ✅ | ✅ | ✅ |
| HTTP/2 / TLS / Stream | ✅ | ✅ | ✅ | ✅ |
DSTW-Nginx / DSTW-OpenResty Server 标记 | ✅ | ✅ | ✅ | ✅ |
| Supervisor 进程管理 | ✅ | ✅ | ✅ | ✅ |
| 配置热加载 | ✅ | ✅ | ✅ | ✅ |
| 日志轮转 | ✅ | ✅ | ✅ | ✅ |
计划任务和 cronctl | ✅ | ✅ | ✅ | ✅ |
/health 健康检查 | ✅ | ✅ | ✅ | ✅ |
40080 状态 vhost | ✅ | ✅ | ✅ | ✅ |
| 空目录默认首页 | ✅ | ✅ | ✅ | ✅ |
| 默认首页诊断码 | ✅ | ✅ | ✅ | ✅ |
| Lua / OpenResty 扩展能力 | - | - | - | ✅ |
docker run -d \
--name nginx \
--restart always \
-p 80:80 \
-p 443:443 \
-p 40080:40080 \
benyoo/nginx:alpine-1.31.1
验证:
curl -fsS http://127.0.0.1/health
curl http://127.0.0.1:40080/nginx_status
docker exec nginx nginx -V
docker run -d \
--name openresty \
--restart always \
-p 80:80 \
-p 443:443 \
-p 40080:40080 \
benyoo/openresty:ubuntu-1.31.1.1
验证:
curl -fsS http://127.0.0.1/health
curl http://127.0.0.1:40080/nginx_status
docker exec openresty nginx -V
项目提供的 compose 模板默认启动 nginx-alpine。其他版本通过 profile 显式启动。所有服务使用 network_mode: host,同一台宿主机一次只建议运行一个版本,切换版本前先 down。
mkdir -p /data
cd /data
curl -fsSL \
-o docker-compose.yml \
https://raw.githubusercontent.com/lookback/docker-nginx/master/docker-compose.yml
如果你的源码仓库使用内网 GitLab,请直接把项目根目录的 docker-compose.yml 放到 /data/docker-compose.yml。
cd /data
docker-compose -f /data/docker-compose.yml up -d
docker-compose -f /data/docker-compose.yml ps
curl -fsS http://127.0.0.1/health
curl http://127.0.0.1:40080/nginx_status
cd /data
docker-compose -f /data/docker-compose.yml down
docker-compose -f /data/docker-compose.yml --profile nginx-ubuntu up -d nginx-ubuntu
可用 profile:
| Profile | 镜像 |
|---|---|
| 默认服务 | benyoo/nginx:alpine-1.31.1 |
nginx-ubuntu | benyoo/nginx:ubuntu-1.31.1 |
nginx-centos | benyoo/nginx:centos-1.31.1 |
openresty-ubuntu | benyoo/openresty:ubuntu-1.31.1.1 |
OpenResty 示例:
cd /data
docker-compose -f /data/docker-compose.yml down
docker-compose -f /data/docker-compose.yml --profile openresty-ubuntu up -d openresty-ubuntu
| 宿主机路径 | 容器路径 | 说明 |
|---|---|---|
/data/wwwroot | /data/wwwroot | 默认网站根目录 |
/data/wwwlogs | /data/wwwlogs | 访问日志和错误日志 |
/data/dstw-diagnostic | /data/dstw-diagnostic | 自动诊断 keypair 持久化目录 |
/data/nginx/conf | /usr/local/nginx/conf | 自定义 NGINX 配置目录,按需挂载 |
| 变量 | 推荐值 | 说明 |
|---|---|---|
TIMEZONE | Asia/Taipei | 容器运行时区 |
DSTW_DEFAULT_INDEX | enable | 空目录时生成默认首页 |
DSTW_DEFAULT_INDEX_SECRET | <replace-with-your-secret> | 默认首页服务端诊断信息加密密钥 |
DSTW_CLIENT_DIAGNOSTIC_PUBLIC_KEY | <shared-diagnostic-key> | 客户端诊断信息加密值,多节点统一排障时建议统一 |
DSTW_CLIENT_DIAGNOSTIC_AUTO_KEYPAIR | disable | 未配置公钥时是否自动生成 keypair |
DSTW_PUBLIC_IP_URL | https://curlip.me https://api.ipify.org | 公网 IP 获取接口列表 |
NGINX_WWWROOT | /data/wwwroot | 默认首页生成目录 |
生产环境必须替换 DSTW_DEFAULT_INDEX_SECRET,不要使用默认值。
当 NGINX_WWWROOT 指向的目录为空时,容器启动会生成一个英文欢迎页,避免空站点访问时出现 403 Forbidden。
默认页包含:
| 区块 | 说明 |
|---|---|
| 欢迎标题 | 用于确认默认首页正常生成 |
| 访问时间 | 按容器时区显示 |
| User-Agent | 现场识别访问客户端 |
| 管理员诊断码 | 复制后提交给管理员排障 |
复制按钮输出格式:
DSTW-DIAG-Z1.<code>
解密完整诊断信息:
docker exec nginx dstw-diagnostic-decrypt \
-s "<DSTW_DEFAULT_INDEX_SECRET>" \
-p "<DSTW_CLIENT_DIAGNOSTIC_PUBLIC_KEY>" \
'DSTW-DIAG-Z1.<code>'
只解服务端信息:
docker exec nginx dstw-decrypt \
-s "<DSTW_DEFAULT_INDEX_SECRET>" \
'DSTW-DIAG-Z1.<code>'
只解客户端信息:
docker exec nginx dstw-client-decrypt \
-p "<DSTW_CLIENT_DIAGNOSTIC_PUBLIC_KEY>" \
'DSTW-DIAG-Z1.<code>'
镜像已编译 HTTP/3 模块:
docker run --rm --entrypoint nginx \
benyoo/nginx:alpine-1.31.1 \
-V 2>&1 | grep -- --with-http_v3_module
业务站点要真正开放 HTTP/3,还需要在 vhost 中配置 QUIC 监听,并确保 UDP 443 可达:
server {
listen 443 ssl;
listen 443 quic reuseport;
http2 on;
ssl_certificate /usr/local/nginx/conf/ssl/example.crt;
ssl_certificate_key /usr/local/nginx/conf/ssl/example.key;
add_header Alt-Svc 'h3=":443"; ma=86400' always;
}
镜像内置状态 vhost,默认监听 40080:
| 路径 | 说明 | 示例 |
|---|---|---|
/health | 健康检查 | curl -fsS http://127.0.0.1/health |
/nginx_status | NGINX stub_status | curl http://127.0.0.1:40080/nginx_status |
/php-fpm_status | PHP-FPM status 代理 | curl http://127.0.0.1:40080/php-fpm_status |
| 命令 | 说明 |
|---|---|
docker exec nginx nginx -t | 检查 NGINX 配置 |
docker exec nginx nginx -s reload | 重新加载 NGINX |
docker exec nginx supervisorctl status | 查看容器内进程状态 |
docker exec nginx cronctl list | 查看计划任务 |
docker exec nginx cronctl add "*/5 * * * *" "/usr/local/nginx/sbin/nginx -t" | 添加计划任务 |
docker exec nginx cronctl reload | 重载计划任务 |
docker exec nginx dstw-diagnostic-decrypt ... | 解密完整诊断包 |
查看远端 manifest:
docker buildx imagetools inspect benyoo/nginx:alpine-1.31.1
docker buildx imagetools inspect benyoo/nginx:ubuntu-1.31.1
docker buildx imagetools inspect benyoo/nginx:centos-1.31.1
docker buildx imagetools inspect benyoo/openresty:ubuntu-1.31.1.1
指定架构拉取:
docker pull --platform linux/amd64 benyoo/nginx:alpine-1.31.1
docker pull --platform linux/arm64 benyoo/nginx:alpine-1.31.1
DSTW_DEFAULT_INDEX_SECRET。DSTW_DEFAULT_INDEX_SECRET 和 DSTW_CLIENT_DIAGNOSTIC_PUBLIC_KEY。/data/wwwroot、/data/wwwlogs 和 /data/dstw-diagnostic。40080 状态端口建议只对可信监控网络开放。443。network_mode: host 时,同一宿主机不要同时运行多个占用相同端口的服务。README.mddocs/README.mddocs/guides/docker-compose.mddocs/guides/02-build-guide.mddocs/guides/pure-nginx-build.mddocs/advanced/multi-arch-build.mddocs/guides/runtime-features.mdSECURITY.mdContent type
Image
Digest
sha256:127a2cf38…
Size
41.1 MB
Last updated
about 4 years ago
docker pull benyoo/nginx