https://github.com/cssnr/docker-nginx-proxy
Docker Nginx Proxy
https://github.com/cssnr/docker-nginx-proxy
docker
Last synced: about 1 month ago
JSON representation
Docker Nginx Proxy
- Host: GitHub
- URL: https://github.com/cssnr/docker-nginx-proxy
- Owner: cssnr
- Created: 2024-08-06T03:03:26.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2026-05-18T04:30:26.000Z (2 months ago)
- Last Synced: 2026-05-18T06:41:27.742Z (2 months ago)
- Topics: docker
- Language: Shell
- Homepage: https://cssnr.github.io
- Size: 24.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
[](https://github.com/cssnr/docker-nginx-proxy/pkgs/container/docker-nginx-proxy)
[](https://github.com/cssnr/docker-nginx-proxy/pkgs/container/docker-nginx-proxy)
[](https://github.com/cssnr/docker-nginx-proxy/tags)
[](https://github.com/cssnr/docker-nginx-proxy/releases)
[](https://github.com/cssnr/docker-nginx-proxy/releases/latest)
[](https://github.com/cssnr/docker-nginx-proxy/releases/latest)
[](https://github.com/cssnr/docker-nginx-proxy/actions/workflows/build.yaml)
[](https://github.com/cssnr/docker-nginx-proxy/actions/workflows/lint.yaml)
[](https://github.com/cssnr/docker-nginx-proxy/pulse)
[](https://github.com/cssnr/docker-nginx-proxy/graphs/contributors)
[](https://github.com/cssnr/docker-nginx-proxy?tab=readme-ov-file#readme)
[](https://github.com/cssnr/docker-nginx-proxy/tree/master/src)
[](https://github.com/cssnr/docker-nginx-proxy/discussions)
[](https://github.com/cssnr/docker-nginx-proxy/forks)
[](https://github.com/cssnr/docker-nginx-proxy/stargazers)
[](https://cssnr.github.io/)
[](https://discord.gg/wXy6m2X8wY)
[](https://ko-fi.com/cssnr)
# Docker Nginx Proxy
Docker Nginx Proxy Container.
This works quite well as is...
```yaml
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
```
## Options
| 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 |
#### Basic Auth
```shell
$ 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.
```yaml
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.
```yaml
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:
```yaml
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](https://docs.docker.com/engine/swarm/) cluster using [Traefik](https://github.com/traefik/traefik).
```yaml
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: true
```
## Support
Please let us know if you run into any [issues](https://github.com/cssnr/docker-nginx-proxy/issues)
or want to see [new features](https://github.com/cssnr/docker-nginx-proxy/discussions/categories/feature-requests)...
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/](https://cssnr.github.io/feedback/)
# Contributing
Please consider making a donation to support the development of this project
and [additional](https://cssnr.com/) open source projects.
[](https://ko-fi.com/cssnr)
If you would like to submit a PR, please review the [CONTRIBUTING.md](#contributing-ov-file).
For a full list of current projects visit: [https://cssnr.github.io/](https://cssnr.github.io/)