Docker Nginx Proxy Container.
This works quite well as is...
services:
nginx:
image: ghcr.io/cssnr/docker-nginx-proxy:latest
environment:
- SERVICE_NAME=app # name of app container
- SERVICE_PORT=8000 # port exposed on app
ports:
- '${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:latest
environment:
- SERVICE_NAME=app
- SERVICE_PORT=3000
ports:
- '${PORT:-80}:80'
app:
image: ghcr.io/smashedr/node-badges:latest
command: 'npm start'
redis:
image: redis:6-alpine
command: 'redis-server --appendonly yes'With the healthcheck:
services:
nginx:
image: ghcr.io/cssnr/docker-nginx-proxy:latest
environment:
- SERVICE_NAME=app
- SERVICE_PORT=3000
healthcheck:
test: ['CMD-SHELL', 'curl -sf localhost:80/health-check || exit 1']
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
ports:
- '${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:latest
environment:
- SERVICE_NAME=app
- SERVICE_PORT=3000
deploy:
mode: global
resources:
limits:
cpus: '1.0'
memory: 64M
labels:
- '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: 30s
timeout: 10s
retries: 3
start_period: 30s
depends_on:
- app
networks:
- internal
- traefik-public
app:
image: ghcr.io/smashedr/node-badges:${VERSION:-latest}
command: 'npm start'
deploy:
mode: global
resources:
limits:
cpus: '2.0'
memory: 256M
healthcheck:
test: ['CMD-SHELL', 'curl -sf localhost:3000/app-health-check || exit 1']
interval: 30s
timeout: 10s
retries: 3
start_period: 30s
depends_on:
- redis
networks:
- internal
redis:
image: redis:6-alpine
command: 'redis-server --appendonly yes'
deploy:
replicas: 1
resources:
limits:
cpus: '1.0'
memory: 128M
volumes:
- redis_data:/data
networks:
- internal
volumes:
redis_data:
networks:
internal:
driver: overlay
traefik-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/