This document describes the custom nginx setup used in this project to enable dynamic vhost configuration using environment variables and Docker Compose.
- Dynamic vhost domain: The nginx config uses
${VHOST_DOMAIN}from the.envfile, allowing you to change the vhost domain without editing config files. - envsubst for templating: The nginx config is generated at container startup using
envsubst, which substitutes environment variables in the config template. - Custom entrypoint: A shell script (
nginx-entrypoint.sh) runsenvsubstand then starts nginx, ensuring the config is always up-to-date with environment variables. - Docker Compose integration: The
VHOST_DOMAINvariable is passed to the nginx container via theenvironmentsection indocker-compose.yml. - .gitignore for generated config: The generated config file (
nginx.vhost.conf.generated) is excluded from version control.
- nginx.vhost.conf.template
- Uses
${VHOST_DOMAIN}for the server_name. - Uses standard nginx variables (e.g.,
$host,$remote_addr).
- Uses
- nginx-entrypoint.sh
- Runs:
envsubst '$VHOST_DOMAIN' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf - Starts nginx in the foreground.
- Runs:
- docker-compose.yml
- Mounts the config template and entrypoint script into the nginx container.
- Sets the entrypoint to
/nginx-entrypoint.sh. - Passes
VHOST_DOMAINfrom.envto the container environment.
- .gitignore
- Excludes
nginx.vhost.conf.generatedfrom version control.
- Excludes
VHOST_DOMAIN=mangareader.local
- Change
VHOST_DOMAINin.envto update the vhost domain. - Recreate the nginx container to apply changes:
docker compose up -d --force-recreate nginx
- If the vhost is not accessible, ensure your
.envis correct and the nginx container is receiving the variable. - Devices on your LAN must resolve the vhost domain to your server's IP (edit hosts file or set up local DNS).
Last updated: 2026-01-29