Skip to content

adrianalin89/nginx-proxy

 
 

Repository files navigation

Nginx-proxy

Test GitHub release nginx 1.27.3 Docker Image Size Docker stars Docker pulls Maintained - Yes

This is a copy of the original repo with some modifications to make it easier to use. Docker-compose for nginx-proxy which is a simple solution for proxying requests to multiple containers. This repo also includes:

Still to come:

Introduction

This project provides a convenient wrapper for nginx-proxy and acme-companion, allowing you to easily develop multiple projects locally with virtual hosts using Docker. It is also ready for live deployment. Additionally, it includes phpmyadmin and mailcatcher for quick debugging, and a global opensearch instance for all projects to reduce unnecessary RAM allocation per project.

Prerequisites

  • Docker
  • Docker Compose

Project Structure

.
├── bin/             # CLI commands
├── certs/           # SSL certificates
├── conf/            # Custom nginx configuration
├── dhparam/         # Diffie-Hellman parameters
├── env/             # Docker environment variables
├── html/            # Default web root
├── images/          # Custom images
├── vhost/           # Virtual host templates
├── README.md        # Project documentation
├── Makefile         # Makefile for CLI commands
├── .env             # Environment variables
├── .gitignore       # Git ignore file
└── docker-compose.yml

CLI Commands

Use the following CLI commands:

  • root: Run any CLI command as root without going into the bash prompt.
  • bash: Drop into the bash prompt of your Docker container.
  • cli: Run any CLI command without going into the bash prompt.
  • docker-compose: Support V1 (docker-compose) and V2 (docker compose) docker compose command, and use custom configuration files.
  • docker-stats: Display status for CPU, memory usage, and memory limit of currently-running Docker containers.
  • log: Monitor the log files. Pass no params to tail all files.
  • restart: Stop and then start all containers.
  • setup: Create the .env file and set the environment variables.
  • start: Start all containers.
  • status: Check the container status.
  • stop: Stop all project containers.
  • update: Update your project to the latest version.

Environment Variables

The following environment variables are used in the .env file:

  • NGINX_PROXY_VERSION: Version of the nginx-proxy image to use.
  • ACME_COMPANION_VERSION: Version of the acme-companion image to use.
  • SELF_SIGNED_VERSION: Version of the self-signed companion image to use.
  • COMPOSE_PROFILES: Compose profiles to use. Possible values: acme, self-signed.
  • USER_ID: User ID for file permissions.
  • GROUP_ID: Group ID for file permissions.

Important

A note on latest and alpine:

It is not recommended to use the latest (nginxproxy/nginx-proxy, nginxproxy/nginx-proxy:latest) or alpine (nginxproxy/nginx-proxy:alpine) tag for production setups.

Those tags point to the latest commit in the main branch. They do not carry any promise of stability, and using them will probably put your nginx-proxy setup at risk of experiencing uncontrolled updates to non backward compatible versions (or versions with breaking changes). You should always specify the version you want to use explicitly to ensure your setup doesn't break when the image is updated.

Compose Profiles

The following compose profiles are available:

  • acme: Use this profile to enable the acme companion for automatic SSL certificate generation.
  • self-signed: Use this profile to enable the self-signed companion for local development with self-signed certificates.

To use a profile, set the COMPOSE_PROFILES variable in the .env file. For example:

COMPOSE_PROFILES=acme

Installation notes

  • Clone project
  • Run the setup script: ./bin/setup
  • Edit the .env file and set the environment variables
  • Start the containers: ./bin/start

Documentation:

  • In conf/custom.conf you can add any custom configuration for nginx.

Example on how to use on containers:

services:
    web:
        ...
        ports:
            - 80
        ...
        environment:
            VIRTUAL_HOST: example.com
            VIRTUAL_PORT: 80
            LETSENCRYPT_HOST: example.com
            LETSENCRYPT_EMAIL: mail@example.com
        ...
        networks:
            ...
            - nginx-proxy

You can use multiple domains/subdomains:

services:
    web:
        ...
        build:
            context: ./
            dockerfile: web/Dockerfile
        ports:
            - 80
        ...
        environment:
            VIRTUAL_HOST: example.com,sub.example.com,example2.com
            VIRTUAL_PORT: 80
            LETSENCRYPT_HOST: example.com,sub.example.com,example2.com
            LETSENCRYPT_EMAIL: mail@example.com
        ...
        networks:
            ...
            - nginx-proxy

When using self-signed companion you need to add SELF_SIGNED_HOST: "example.com" environment variable as well

  • In web/Dockerfile you can include a conf where you define your servers, wildcards are not yet supported by acme companion.
  • Self-signed companion should be used only on a local environment.
  • To use self-signed companion change COMPOSE_PROFILES to self-signed in .env

Trust self-signed certificates

To avoid the alert "your connection is not private" please check self-signed repo: https://github.com/sebastienheyd/docker-self-signed-proxy-companion

Use certificates with vite server

In order to use certification in an application you need to change ownership to <user>:<group> for folder certs after certificates generation and map certs as read only volume where you want to use certs.

Additional documentation

Please check the docs section.

Email / Mailcatcher

View emails sent locally through Mailcatcher by visiting http://{yourdomain}:1080. In order to use mailcatcher, set the mailserver host to mailcatcher and set port to 1025. Note that this port (1025) is different from the mailcatcher interface to read the emails (1080).

Alternative tools to test emails and get some metrics: mailtrap

PhpMyAdmin

PhpMyAdmin is built into the project file. Simply open http://localhost:8080 in a web browser.

These credentials can be used to log in to PhpMyAdmin are specified in each project .env file.

Troubleshooting

  • Error: SSL certificate not working
    Check if COMPOSE_PROFILES is set correctly in the .env file.

  • Error: nginx-proxy container keeps restarting
    Ensure you don't have conflicting ports on the host machine.

  • Error: Let's Encrypt SSL certificates not being generated
    Verify your domain is properly pointed to the server's IP address and publicly accessible.

  • Error: docker-compose command not found
    Ensure you have Docker Compose installed.

Contributions

Want to make this project better? Feel free to submit a PR or open an issue. We promise not to ignore it (too much).

Contact Information

If you're stuck or have questions:

  • Option 1: Read the docs until you question your life choices.
  • Option 2: Open an issue and pray someone answers before the next millennium.
  • Option 3: Offer cookies or coffee, and maybe, just maybe, someone will help.

htpasswd -c ./htpasswd/[foo.bar] [username] replace [foo.bar] and [username] whit domain and username

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 75.2%
  • Makefile 23.1%
  • Dockerfile 1.7%