Base Nginx image for Drupal with optimized configuration
697
A base Nginx image for Drupal production environments with Drupal-optimized configuration and a pre-configured drupal user. Designed to pair with drupal-php.
drupal user with configurable UID/GIDCache-Control: public, immutablelatestdocker pull tavib47/drupal-nginx
This image is designed to be extended in your project:
FROM tavib47/drupal-nginx
# Copy static assets
COPY --chown=drupal:drupal web/ /var/www/html/web/
# Optionally override the nginx config template
# COPY docker/nginx/default.conf.template /etc/nginx/templates/default.conf.template
ENV ROBOTS_FILE=robots.txt
| Variable | Default | Description |
|---|---|---|
PHP_FPM_HOST | php | PHP-FPM container hostname |
PHP_FPM_PORT | 9000 | PHP-FPM port |
ROBOTS_FILE | robots.txt | Robots file path (for multi-site setups) |
NGINX_CLIENT_MAX_BODY_SIZE | 50M | Max upload/POST body size |
NGINX_FASTCGI_CONNECT_TIMEOUT | 60s | FastCGI connect timeout |
NGINX_FASTCGI_SEND_TIMEOUT | 60s | FastCGI send timeout |
NGINX_FASTCGI_READ_TIMEOUT | 300s | FastCGI read timeout (increase for long-running requests) |
| ARG | Default | Description |
|---|---|---|
DRUPAL_UID | 41821 | UID for the drupal user |
DRUPAL_GID | 41821 | GID for the drupal group |
services:
php:
image: tavib47/drupal-php:8.4
volumes:
- .:/var/www/html
expose:
- "9000"
nginx:
build:
context: .
dockerfile: docker/nginx/Dockerfile
args:
- DRUPAL_UID=${DRUPAL_UID:-41821}
- DRUPAL_GID=${DRUPAL_GID:-41821}
ports:
- "80:80"
volumes:
- ./web:/var/www/html/web:ro
environment:
- PHP_FPM_HOST=php
- PHP_FPM_PORT=9000
- NGINX_CLIENT_MAX_BODY_SIZE=100M
- NGINX_FASTCGI_READ_TIMEOUT=600s
depends_on:
- php
The default configuration includes the following security headers:
X-Frame-Options: SAMEORIGIN — Prevents clickjackingX-Content-Type-Options: nosniff — Prevents MIME type sniffingReferrer-Policy: strict-origin-when-cross-origin — Controls referrer informationStrict-Transport-Security: max-age=31536000 — Enforces HTTPS (HSTS)The default configuration includes Drupal security best practices:
.txt and .log filessites/*/files/private/ directories.well-known/)vendor/ and node_modules/ directories.engine, .inc, .install, .module, .env, .yml, .yaml, .sql, .bak, etc.)server_tokens off)Configured to extract real client IP from X-Forwarded-For header when behind a reverse proxy. Supports common private IP ranges:
10.0.0.0/8172.16.0.0/12192.168.0.0/16127.0.0.1To override the default server configuration, copy your template:
FROM tavib47/drupal-nginx
COPY my-default.conf.template /etc/nginx/templates/default.conf.template
The template supports environment variable substitution via nginx's envsubst.
Content type
Image
Digest
sha256:057ccf461…
Size
24.8 MB
Last updated
8 months ago
docker pull tavib47/drupal-nginx