A nginx docker image with secure configurations and some useful modules.
10K+
A nginx docker image with secure configurations and some useful modules, such as ngx_http_geoip_module, ngx_http_image_filter_module, ngx_http_perl_module, ngx_http_xslt_filter_module, ngx_mail_module, ngx_stream_geoip_module, ngx_stream_module, ngx-fancyindex, headers-more-nginx-module, etc.
Build with the linux/arm64, linux/386, linux/amd64, linux/arm/v6, linux/arm/v7, linux/arm64/v8 architectures.
Already installed modules:
More modules can be found in Dockerfile.
docker pull funnyzak/nginx:latest
# GHCR
docker pull ghcr.io/funnyzak/nginx:latest
# Aliyun
docker pull registry.cn-beijing.aliyuncs.com/funnyzak/nginx:latest
First, create a nginx.conf file in your project directory, and then run the following command:
# Run nginx container with default settings
docker run -d -t -i --name nginx --restart on-failure \
-p 1697:80 \
funnyzak/nginx
# Run nginx container with custom configuration directory
docker run -d -t -i --name nginx2 --restart on-failure \
-v ./nginx/conf.d:/etc/nginx/conf.d \
-p 1688:80 \
funnyzak/nginx
# Run nginx container with custom HTML directory
docker run -d -t -i --name nginx3 --restart on-failure \
-v ./nginx/html:/etc/nginx/html \
-p 1690:80 \
funnyzak/nginx
# Run nginx container with environment-variable-driven default server config
docker run -d -t -i --name nginx4 --restart on-failure \
-e NGINX_SERVER_NAME=example.com \
-e NGINX_LISTEN_PORT=8080 \
-p 18080:8080 \
funnyzak/nginx
On first start, if you do not mount your own conf.d, the image renders /etc/nginx/templates/default.conf.template into /etc/nginx/conf.d/default.conf. The entrypoint checks /etc/nginx/templates/default.conf.template first and then falls back to /data/nginx/templates/default.conf.template. The built-in static default.conf is kept under /data/nginx/conf.d as a fallback when template rendering is unavailable.
The built-in template has these defaults:
NGINX_LISTEN_PORT: listen port, default 80NGINX_SERVER_NAME: server name, default _NGINX_WEB_ROOT: root path used by location /, default htmlNGINX_INDEX_FILES: index files, default index.html index.htmNGINX_SERVER_BUILD: value used in Server-Build response header, default build via @funnyzakFor custom mounted templates, the entrypoint will automatically detect and render every placeholder written as ${ENV_NAME}. This means you can define any container environment variable and reference it directly in your own default.conf.template without changing the image script.
Example:
docker run -d --name nginx-template \
-e APP_DOMAIN=demo.local \
-e APP_UPSTREAM=http://host.docker.internal:3000 \
-v ./default.conf.template:/etc/nginx/templates/default.conf.template \
-p 8080:80 \
funnyzak/nginx
server {
listen 80;
server_name ${APP_DOMAIN};
location / {
proxy_pass ${APP_UPSTREAM};
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Use ${ENV_NAME} for environment placeholders. Nginx runtime variables like $host and $remote_addr can stay unchanged.
If you mount your own non-empty /etc/nginx/conf.d, the container will not overwrite it with the template. If you mount your own default.conf.template, it will be rendered only when /etc/nginx/conf.d is empty.
First, create a docker-compose.yml file in your project directory:
version: “3.3”
services:
nginx:
image: funnyzak/nginx
container_name: nginx
environment:
- TZ=Asia/Shanghai
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
restart: on-failure
ports:
- “1688:80”
Then, run the following command:
docker-compose up -d
docker build \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
--build-arg VERSION="1.27.3" \
-t funnyzak/nginx:1.27.3 .
Content type
Image
Digest
sha256:65deac65e…
Size
31.4 MB
Last updated
6 days ago
docker pull funnyzak/nginx