This project provides a Docker Compose setup for nginx-proxy with optional support for acme-companion and self-signed-proxy-companion. It enables easy development of multiple projects locally with virtual hosts using Docker and is also ready for live deployment.
- Docker Engine & Docker Compose
- Git
- Linux or Windows WSL2
- Clone the repository
git clone https://github.com/ionghitun/nginx-proxy.git cd nginx-proxy
- Copy and configure environment variables
cp scripts/.env.example scripts/.env export USER_ID=$(id -u) export GROUP_ID=$(id -g) # Edit other variables in scripts/.env as needed
- Create global nginx-proxy network
docker network create nginx-proxy
- Start the project
sh scripts/start.sh
Conf Configuration: Edit conf/custom.conf
- acme: Enables automatic SSL certificate generation using Let's Encrypt via acme-companion.
- self-signed: Enables self-signed SSL certificate generation for local development via self-signed-proxy-companion.
- leave COMPOSE_PROFILES empty to run only nginx-proxy without SSL support.
To enable virtual hosting for your containers, set port, environment and network:
services:
...
nginx:
...
ports:
- 80
- ...
environment:
VIRTUAL_HOST: example.com
VIRTUAL_PORT: 80
LETSENCRYPT_HOST: example.com
LETSENCRYPT_EMAIL: [email protected]
...
networks:
- nginx-proxy
- ...
For multiple domains or subdomains:
VIRTUAL_HOST: example.com,sub.example.com,example2.com
VIRTUAL_PORT: 80
LETSENCRYPT_HOST: example.com,sub.example.com,example2.com
LETSENCRYPT_EMAIL: [email protected]
When using the self-signed companion, add extra the SELF_SIGNED_HOST
environment variable:
environment:
SELF_SIGNED_HOST: example.com
To avoid browser warnings like "Your connection is not private" when using self-signed certificates, refer to the self-signed-proxy-companion documentation for instructions on trusting these certificates in your local environment.
To use SSL certificates in applications like Vite, mount the certs directory as a read-only volume in your application container:
To have permissions to use, hosts must end in .local
volumes:
- /path/to/nginx-proxy/certs:/path/in/container/certs:ro
./scripts/start.sh # Start the containers
./scripts/down.sh # Stop the containers
./scripts/build.sh # Build or rebuild the containers
./scripts/restart.sh # Restart the containers
- Permission Issues: Ensure
USER_ID
andGROUP_ID
inscripts/.env
match your host user IDs. - Docker Issues: For older versions you might want to remove
COMPOSE_BAKE
from.env
. - Docker Compose Issues: Please update and ensure you can use
docker compose
, not old versiondocker-compose
This project is licensed under the MIT License. See LICENSE for details.
Contributions are welcome! Please open issues or submit pull requests following the repository guidelines.
Happy Coding