This project demonstrates the use of Traefik as a reverse proxy to manage two Node.js applications, load balancing, and health checks. It allows you to expose multiple applications securely with automatic HTTPS certificates and ensures high availability.
Before getting started, make sure you have the following dependencies installed:
-
Clone this repository to your local machine:
git clone https://github.com/J-hune/traefik-load-balancer.git
-
Navigate to the project directory:
cd traefik-load-balancer
-
Create a
.env
file by making a copy of the provided.env.example
:cp .env.example .env
-
Modify the
.env
file with your preferred settings:DOMAIN_NAME
: Set your domain name.ACME_EMAIL
: Provide your email for Let's Encrypt certificate registration.LOG_LEVEL
: (Optional) Set the log level (e.g., INFO, DEBUG).
-
Start the project using Docker Compose:
docker compose up -d
-
The project will now be running, and Traefik will handle routing, load balancing, and health checks for your applications.
You can access your applications through the following URLs:
- App 1: http://app1.DOMAIN_NAME
- App 2: http://app2.DOMAIN_NAME
Replace DOMAIN_NAME
with the domain name you specified in your .env
file.
The applications now have health checks in place. Each application exposes a /health
endpoint, which Traefik uses to ensure their availability. Traefik will automatically route traffic only to healthy instances of the applications.
Traefik provides a dashboard to monitor and manage your routing configuration. You can access it at http://localhost. Note that it's recommended to secure the Traefik dashboard in a production environment.
This project is licensed under the MIT License. See the LICENSE file for details.
Happy reverse proxying!