Skip to content

A production-ready Central Gateway boilerplate using Nginx and Docker Compose.

License

Notifications You must be signed in to change notification settings

akccakcctw/docker-nginx-central-gateway

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker Nginx Central Gateway

A production-ready Central Gateway boilerplate using Nginx and Docker Compose. It handles:

  • Reverse Proxy: Routing traffic to different Dockerized applications on the same host.
  • SSL Termination: Automatic HTTPS with Let's Encrypt (Certbot).
  • Zero Downtime: Reload configurations without stopping services.

Architecture

This setup uses an external Docker network named proxy-net.

  • Gateway (Nginx): Runs on proxy-net and handles ports 80/443.
  • Your Apps: Run on proxy-net (internal only) and are reachable by Nginx via container names.

Prerequisites

  1. Install Docker & Docker Compose.
  2. Create the shared network (required once per host):
    docker network create proxy-net

Directory Structure

gateway/
├── docker-compose.yml
├── nginx/
│   └── conf.d/
│       ├── default.conf         # Health check & fallback
│       └── app.conf.example     # Template for your apps
├── tests/
│   └── verify_setup.py          # Infrastructure verification
└── LICENSE

Quick Start

  1. Clone and Start:

    git clone <your-repo-url> gateway
    cd gateway
    docker compose up -d
  2. Verify: Visit http://localhost (or your server IP). You should see "Gateway is running!".

Adding a New App (Step-by-Step)

  1. Prepare Nginx Config: Copy the example and edit it:

    cp nginx/conf.d/app.conf.example nginx/conf.d/my-app.conf

    Edit my-app.conf: Change app.example.com to your actual domain and update the proxy_pass upstream.

  2. Get SSL Certificate:

    docker compose run --rm certbot certonly --webroot --webroot-path=/var/www/certbot -d yourdomain.com
  3. Reload Nginx:

    docker compose exec nginx nginx -s reload

Migration Guide

How to move an existing standalone app to this gateway architecture.

Before (Standalone App): The app handles its own ports and SSL.

services:
  web:
    image: your-username/my-web-app:latest
    ports:
      - "80:80" # ❌ Remove this
      - "443:443" # ❌ Remove this

After (Gateway-Ready): Connect to proxy-net and remove port bindings.

services:
  web:
    image: your-username/my-web-app:latest
    restart: unless-stopped
    environment:
      - PORT=3000
    networks:
      - proxy-net  # ✅ Connect to gateway
    # ports: ... (Removed)

networks:
  proxy-net:
    external: true

Testing

Run the verification script to check your folder structure:

python3 tests/verify_setup.py

About

A production-ready Central Gateway boilerplate using Nginx and Docker Compose.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages