Skip to content

Repository files navigation

Image SizeImage LatestGitHub Tag MajorGitHub Tag MinorGitHub Tag ReleaseGitHub Release VersionWorkflow BuildWorkflow LintGitHub Last CommitGitHub ContributorsGitHub Repo SizeGitHub Top LanguageGitHub DiscussionsGitHub ForksGitHub Repo StarsGitHub Org StarsDiscordKo-fi

Docker Nginx Proxy

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

Options

VariableDefaultDescription of Environment Variable
SERVICE_NAMEappHostname (service name) of container
SERVICE_PORT8000Port service/container is listening on
GZIP_TYPES-Nginx content gzip_types to compress
GZIP_LENGTH1000Minimum content size to compress
BASIC_AUTH-Basic auth file contents
BASIC_REALMUnauthorizedMinimum content size to compress

Basic Auth

$ htpasswd -nb user pass
user:$apr1$XFVN0nJA$IgZxtMHVAeA.Pu7ufU7/I0

Replace 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.

Examples

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: true

Support

Please let us know if you run into any issues or want to see new features...

For general help or to request a feature:

If you are experiencing an issue/bug or getting unexpected results:

Contributing

Please consider making a donation to support the development of this project and additional open source projects.

Ko-fi

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/

About

Docker Nginx Proxy

Topics

Resources

Contributing

Stars

1 star

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages