Docker Nginx Proxy Container.
This works quite well as is...
services:
nginx:
image: ghcr.io/cssnr/docker-nginx-proxy:latestenvironment:
- SERVICE_NAME=app # name of app container
- SERVICE_PORT=8000 # port exposed on appports:
- '${PORT:-80}:80'# Host PORT : Container (must be :80)app:
image: your-app-image # listens on port 8000| Variable | Default | Description of Environment Variable |
|---|---|---|
| SERVICE_NAME | app | Hostname (service name) of container |
| SERVICE_PORT | 8000 | Port service/container is listening on |
| GZIP_TYPES | - | Nginx content gzip_types to compress |
| GZIP_LENGTH | 1000 | Minimum content size to compress |
| BASIC_AUTH | - | Basic auth file contents |
| BASIC_REALM | Unauthorized | Minimum content size to compress |
$ htpasswd -nb user pass
user:$apr1$XFVN0nJA$IgZxtMHVAeA.Pu7ufU7/I0Replace all $ with $$ for docker-compose.yaml files.
Use \n for newlines to add multiple credentials.
environment:
BASIC_AUTH: 'user:$$apr1$$XFVN0nJA$$IgZxtMHVAeA.Pu7ufU7/I0\nuser2:$$apr1$$vswJgdwo$$2XkDOrvJFQ2pKwrXqGeWM0'AI is Retarded.
If your app container is called app and listens on 3000 this will reverse proxy it to the PORT exposed on nginx.
services:
nginx:
image: ghcr.io/cssnr/docker-nginx-proxy:latestenvironment:
- SERVICE_NAME=app
- SERVICE_PORT=3000ports:
- '${PORT:-80}:80'app:
image: ghcr.io/smashedr/node-badges:latestcommand: 'npm start'redis:
image: redis:6-alpinecommand: 'redis-server --appendonly yes'With the healthcheck:
services:
nginx:
image: ghcr.io/cssnr/docker-nginx-proxy:latestenvironment:
- SERVICE_NAME=app
- SERVICE_PORT=3000healthcheck:
test: ['CMD-SHELL', 'curl -sf localhost:80/health-check || exit 1']interval: 30stimeout: 10sretries: 3start_period: 30sports:
- '${PORT:-80}:80'First example, but deployed to a Docker Swarm cluster using Traefik.
version: '3.8'services:
nginx:
image: ghcr.io/cssnr/docker-nginx-proxy:latestenvironment:
- SERVICE_NAME=app
- SERVICE_PORT=3000deploy:
mode: globalresources:
limits:
cpus: '1.0'memory: 64Mlabels:
- 'traefik.enable=true'
- 'traefik.docker.network=traefik-public'
- 'traefik.constraint-label=traefik-public'
- 'traefik.http.routers.${STACK_NAME?err}-http.rule=Host(`${TRAEFIK_HOST?err}`)'
- 'traefik.http.routers.${STACK_NAME}-http.entrypoints=http'
- 'traefik.http.routers.${STACK_NAME}-http.middlewares=${STACK_NAME}-http-redirect'
- 'traefik.http.middlewares.${STACK_NAME}-http-redirect.redirectscheme.scheme=https'
- 'traefik.http.middlewares.${STACK_NAME}-http-redirect.redirectscheme.permanent=true'
- 'traefik.http.routers.${STACK_NAME}-https.rule=Host(`${TRAEFIK_HOST}`)'
- 'traefik.http.routers.${STACK_NAME}-https.entrypoints=https'
- 'traefik.http.routers.${STACK_NAME}-https.tls=true'
- 'traefik.http.services.${STACK_NAME}.loadbalancer.server.port=80'
- 'traefik.http.services.${STACK_NAME}.loadbalancer.server.scheme=http'healthcheck:
test: ['CMD-SHELL', 'curl -sf localhost:80/health-check || exit 1']interval: 30stimeout: 10sretries: 3start_period: 30sdepends_on:
- appnetworks:
- internal
- traefik-publicapp:
image: ghcr.io/smashedr/node-badges:${VERSION:-latest}command: 'npm start'deploy:
mode: globalresources:
limits:
cpus: '2.0'memory: 256Mhealthcheck:
test: ['CMD-SHELL', 'curl -sf localhost:3000/app-health-check || exit 1']interval: 30stimeout: 10sretries: 3start_period: 30sdepends_on:
- redisnetworks:
- internalredis:
image: redis:6-alpinecommand: 'redis-server --appendonly yes'deploy:
replicas: 1resources:
limits:
cpus: '1.0'memory: 128Mvolumes:
- redis_data:/datanetworks:
- internalvolumes:
redis_data:
networks:
internal:
driver: overlaytraefik-public:
external: truePlease let us know if you run into any issues or want to see new features...
For general help or to request a feature:
- Q&A Discussion: https://github.com/cssnr/docker-nginx-proxy/discussions/categories/q-a
- Request a Feature: https://github.com/cssnr/docker-nginx-proxy/discussions/categories/feature-requests
If you are experiencing an issue/bug or getting unexpected results:
- Report an Issue: https://github.com/cssnr/docker-nginx-proxy/issues
- Chat with us on Discord: https://discord.gg/wXy6m2X8wY
- Provide General Feedback: https://cssnr.github.io/feedback/
Please consider making a donation to support the development of this project and additional open source projects.
If you would like to submit a PR, please review the CONTRIBUTING.md.
For a full list of current projects visit: https://cssnr.github.io/