Skip to content

ionghitun/nginx-proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nginx-Proxy Stack

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.

Prerequisites

  • Docker Engine & Docker Compose
  • Git
  • Linux or Windows WSL2

Installation

  1. Clone the repository
    git clone https://github.com/ionghitun/nginx-proxy.git
    cd nginx-proxy
  2. 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
  3. Create global nginx-proxy network
    docker network create nginx-proxy
  4. Start the project
    sh scripts/start.sh

Configuration

Conf Configuration: Edit conf/custom.conf

Compose Profiles

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

Example: Using Virtual Hosts in Containers

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

Trusting Self-Signed Certificates

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.

Using Certificates with Vite Server

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

Available scripts

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

Troubleshooting

  • Permission Issues: Ensure USER_ID and GROUP_ID in scripts/.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 version docker-compose

License

This project is licensed under the MIT License. See LICENSE for details.

Contributing

Contributions are welcome! Please open issues or submit pull requests following the repository guidelines.

Happy Coding

About

Example using docker-compose with nginx-proxy and acme companion.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published