A small, hardened nginx image built from source: HTTP/1.1, HTTP/2 and HTTP/3 (QUIC) on the standard ports, running entirely as a non-root user.
docker run -d --name nginx \
-p 80:80/tcp -p 443:443/tcp -p 443:443/udp \
imzami/nginx:latestOpen https://localhost/. With no certificate mounted the image generates a self-signed one, so the browser will warn; see Certificates.
The same image, with the same tags, is published to two registries:
| Registry | Image |
|---|---|
| Docker Hub | imzami/nginx (docker.io/imzami/nginx) |
| GitHub Container Registry | ghcr.io/rtlbd/nginx |
| HTTP/1.1, HTTP/2, HTTP/3 | All three on every HTTPS site. HTTP/3 is advertised to browsers through the Alt-Svc header. |
| QUIC | UDP 443 with reuseport and generic segmentation offload (quic_gso). |
| TLS 1.2 and 1.3 only | Modern AEAD cipher suites; older protocols are refused. |
| Post-quantum key exchange | X25519MLKEM768 hybrid group is preferred, with classical fallbacks. |
| HTTP → HTTPS redirect | Port 80 answers with 308 to the same URL on HTTPS. |
| IPv4 and IPv6 | The default site enables its IPv6 listeners automatically when the container has IPv6 (with a read-only root filesystem it stays on IPv4; list [::] in your own site files). |
Ports: 80/tcp, 443/tcp, 443/udp.
- Non-root. Master and worker processes run as UID/GID
101(nginx). There is no root process in the container at any point. - Read-only root filesystem. Only
/tmphas to be writable. - No capabilities needed. Runs with
--cap-drop=ALLand--security-opt no-new-privileges. - No version disclosure.
server_tokens off, and theServerheader is removed completely. - Security headers as a snippet:
X-Content-Type-Options,X-Frame-Options,Referrer-Policy; HSTS as a separate opt-in snippet. - Rate and connection limits per client IP, ready to switch on with one
include. - Strict catch-all server example that refuses the TLS handshake for unknown host names.
- Pinned sources. The nginx tarball is verified by SHA-256 and the modules are pinned to full git commits.
- Small. About 32 MB, Alpine based.
- Brotli and gzip compression, including pre-compressed
.br/.gzfiles. sendfile,tcp_nopush, long keep-alives, open-file cache, PCRE JIT.- One worker per CPU core, 4096 connections per worker.
- TLS session cache shared between workers.
- Health check built in.
HEALTHCHECKuses an internal listener on127.0.0.1:8080, so it keeps working whatever site configuration you mount.stub_statusis on the same listener at/nginx_status. - Works out of the box. A self-signed certificate is generated at start-up if none is mounted.
- Environment templates.
/etc/nginx/templates/*.templatefiles are rendered withenvsubstinto/etc/nginx/conf.d/. - Start-up hooks. Executable
*.shfiles in/docker-entrypoint.d/run before nginx. - Logs to stdout/stderr, with an optional JSON access-log format.
- Graceful shutdown on
docker stop(SIGQUIT). - Multi-arch.
linux/amd64,linux/arm64andlinux/arm/v7(32-bit ARM, such as a Raspberry Pi with a 32-bit OS).
http_ssl, http_v2, http_v3, http_realip, http_gzip_static, http_gunzip, http_stub_status, http_auth_request, http_addition, http_sub, http_slice, http_secure_link, stream, stream_ssl, stream_ssl_preread, stream_realip, plus the third-party ngx_brotli and headers-more.
services:
nginx:
image: imzami/nginx:latest
restart: unless-stopped
ports:
- "80:80/tcp"
- "443:443/tcp"
- "443:443/udp" # HTTP/3 (QUIC)
read_only: true
cap_drop: [ALL]
security_opt: ["no-new-privileges:true"]
tmpfs:
- /tmp
volumes:
- ./conf.d:/etc/nginx/conf.d:ro
- ./certs:/etc/nginx/certs:roThe same file is in examples/docker-compose.yml.
Docker allows unprivileged processes to bind low ports inside a container's own network namespace, so the default bridge network and Compose need nothing extra.
Two setups do need a setting:
-
Host networking (
--network host): the host's own limit applies. Setnet.ipv4.ip_unprivileged_port_start=0on the host. -
Kubernetes: add the sysctl to the pod.
securityContext: runAsNonRoot: true runAsUser: 101 sysctls: - name: net.ipv4.ip_unprivileged_port_start value: "0"
- Publish UDP 443 as well as TCP 443, and open it in the firewall or security group.
- The
Alt-Svcheader must name the port clients connect to. If you publish a different port (for example-p 8443:443/udp), editsnippets/http3.confto match. - Browsers only switch to HTTP/3 with a certificate they trust. A self-signed certificate keeps them on HTTP/2.
| Path | Purpose |
|---|---|
/etc/nginx/nginx.conf |
Main configuration: TLS, compression, logging, limits. |
/etc/nginx/conf.d/*.conf |
Your sites. The image ships default.conf; replace it. |
/etc/nginx/snippets/ |
Reusable pieces to include (below). |
/etc/nginx/certs/ |
Certificates. |
/etc/nginx/templates/ |
*.template files rendered into conf.d at start-up. |
/usr/share/nginx/html/ |
Static files of the default site. |
/docker-entrypoint.d/ |
Start-up scripts. |
| Snippet | Use in | What it does |
|---|---|---|
snippets/http3.conf |
server |
Alt-Svc header announcing HTTP/3. |
snippets/security-headers.conf |
server |
nosniff, frame and referrer policies. |
snippets/hsts.conf |
server |
Strict-Transport-Security for one year. |
snippets/rate-limit.conf |
server / location |
20 requests/s (burst 40) and 50 connections per IP. |
snippets/proxy.conf |
location |
Reverse-proxy headers and WebSocket upgrade. |
snippets/static-cache.conf |
location |
One-year immutable caching for fingerprinted assets. |
add_header_inherit merge is set globally, so headers from these snippets are kept when a location adds its own.
Start from examples/site.conf (reverse proxy) and examples/catch-all.conf (strict default server). One rule matters for HTTP/3:
reuseportmay be given only once per address and port. The default server carries it; every other site uses plainlisten 443 quic;.
The default site reads /etc/nginx/certs/fullchain.pem and /etc/nginx/certs/privkey.pem. Mount your own there; they must be readable by UID 101.
docker run -d -p 80:80 -p 443:443/tcp -p 443:443/udp \
-v /path/to/certs:/etc/nginx/certs:ro \
imzami/nginx:latestIf both files are missing, a self-signed certificate is created at start-up. With a read-only root filesystem that needs a writable /etc/nginx/certs, for example --tmpfs /etc/nginx/certs:uid=101,gid=101.
After renewing a certificate, reload without dropping connections:
docker exec nginx nginx -s reload| Variable | Default | Effect |
|---|---|---|
NGINX_SELF_SIGNED_CN |
localhost |
Host name in the generated self-signed certificate. |
NGINX_ENTRYPOINT_QUIET_LOGS |
unset | Set to 1 to silence start-up script output. |
NGINX_ENVSUBST_TEMPLATE_DIR |
/etc/nginx/templates |
Where templates are read from. |
NGINX_ENVSUBST_OUTPUT_DIR |
/etc/nginx/conf.d |
Where rendered files are written. |
NGINX_ENVSUBST_TEMPLATE_SUFFIX |
.template |
Suffix stripped from template names. |
In templates, ${NAME} is replaced only when NAME is set in the environment, so nginx's own variables ($host, $uri) are left alone.
access_log /var/log/nginx/access.log json;Pushing a version tag publishes the image to GitHub Container Registry and, once it is set up, to Docker Hub:
git tag v1.31.10
git push origin v1.31.10The release workflow builds the image, runs the smoke test and the vulnerability scan, then builds for amd64, arm64 and arm/v7 and pushes it to every configured registry with an SBOM and build provenance attached. Both registries always get the same image and the same tags.
Releases go to imzami/nginx. To set it up:
-
On Docker Hub, create the repository
nginxunderimzami. -
In this GitHub repository, open Settings → Secrets and variables → Actions and add:
Name Kind Value DOCKERHUB_USERNAMEvariable or secret imzamiDOCKERHUB_PASSWORDsecret the Docker Hub password of that user DOCKERHUB_IMAGEvariable, optional only to push somewhere else, such as myorg/nginx; defaults to<DOCKERHUB_USERNAME>/nginx, hereimzami/nginx -
Push a release tag, or run the Release workflow manually to publish the current release there too.
With neither DOCKERHUB_USERNAME nor DOCKERHUB_PASSWORD set, releases go to GHCR only and the run shows a warning. Setting only one of them fails the release, so a typo cannot silently skip Docker Hub.
CI also logs in to Docker Hub with the same credentials when they are set, which lifts the anonymous pull limit for the Alpine base image.
A release tag is the nginx version, v<nginx version>. For another release of the same nginx (a configuration fix, for example) append a revision number: v1.31.10-1, then v1.31.10-2.
| Git tag | Image tags |
|---|---|
v1.31.10 |
1.31.10, 1.31, 1, latest |
v1.31.10-2 |
1.31.10-2, 1.31.10, 1.31, 1, latest |
v1.31.11-rc.1 (anything else) |
1.31.11-rc.1 only |
The workflow refuses a release tag that does not match NGINX_VERSION in the Dockerfile.
Every Monday the workflow scans the latest published release. If any of its Alpine packages has a fix available, that release is rebuilt from the same source with current packages, tested, and republished under the same image tags on every registry. If nothing needs fixing, nothing is published.
Image tags therefore move to newer builds over time. To stay on one exact build, pin the image by digest (imzami/nginx@sha256:..., or the same digest on ghcr.io/rtlbd/nginx).
To rebuild on demand, run the Release workflow manually from the Actions tab; that always rebuilds the latest release.
The first publish creates the package as private. To make it pullable without login, open the package on GitHub → Package settings → Change visibility.
All versions are set at the top of the Dockerfile:
| Line | What to set |
|---|---|
FROM alpine:<version> |
Alpine release (Dependabot proposes updates). |
NGINX_VERSION |
Version from https://nginx.org/en/download.html. |
NGINX_SHA256 |
sha256sum of that nginx-<version>.tar.gz. |
NGX_BROTLI_COMMIT |
Full commit of google/ngx_brotli. |
HEADERS_MORE_COMMIT |
Full commit of openresty/headers-more-nginx-module. |
Change them, push, let CI pass, then tag a release with the new nginx version.
docker build -t nginx:dev .
tests/smoke.sh nginx:devThe smoke test starts the image read-only with all capabilities dropped and checks the user, all three HTTP versions, compression, headers, the health check and graceful shutdown. The HTTP/3 check needs pip install -r tests/requirements.txt; without it that one check is skipped.
CI runs on every push and pull request:
- Lint: hadolint for the Dockerfile, ShellCheck for the scripts, actionlint for the workflows.
- Build and smoke test on
amd64andarm64on native runners, and onarm/v7under QEMU emulation. - Vulnerability scan with Trivy: fails on any finding in the image's Alpine packages that has a fix available, whatever its severity. The build runs
apk upgrade, so every fixed package Alpine has published is in the image. nginx itself and the two modules are compiled from source, so they are not covered by the scan; keep them current through the pinned versions above. - Docker Scout scan with the same rule, when the Docker Hub credentials are set. Both scanners check every platform (
amd64,arm64,arm/v7). Scout is what Docker Hub shows for the image and its data can differ from Trivy's, so both have to pass. The log also shows Scout's current report for the published image.
Dependabot opens weekly pull requests for new versions of the GitHub Actions, the Alpine base image and the test dependencies.
Official nginx |
This image | |
|---|---|---|
| User | root master, nginx workers |
everything as UID 101 |
| HTTP/3 | compiled in, not configured | configured on the default site |
| Brotli, headers-more | not included | compiled in |
Server header |
nginx |
removed |
| Read-only root filesystem | needs extra mounts | needs only /tmp |
| pid and temp files | /var/run, /var/cache/nginx |
/tmp |
| Dynamic modules (njs, GeoIP, image filter, XSLT, ACME) | available in the full variant | not included |
The files in this repository are released under the MIT License.
The image contains software under its own licenses, among others nginx (BSD-2-Clause), ngx_brotli (BSD-2-Clause), Brotli (MIT), headers-more (BSD-2-Clause), OpenSSL (Apache-2.0) and the Alpine Linux packages.