/nginx-proxy-lb

A practical repository for setting up a reverse proxy, load balancer, and rate limiter using NGINX, with monitoring powered by Spring Actuator, Prometheus, and Grafana. Includes Docker Compose for easy deployment and a sample Spring Boot backend. Perfect for exploring modern application scalability and monitoring techniques!

Primary LanguageJavaMIT LicenseMIT

πŸ‡ΊπŸ‡Έ Nginx Proxy Load Balancer

This repository provides a practical setup for implementing a load balancer, a rate limiter using NGINX, as well as a circuit breaker and monitoring with Spring Actuator, Prometheus, and Grafana.


πŸš€ How to Use

1. Prerequisites

  • Docker and Docker Compose installed.
  • Access to backend instances (applications that will receive balanced traffic).

2. Clone the Repository

git clone https://github.com/MSpilari/nginx-proxy-lb.git
cd nginx-proxy-lb

3. Start the Service with Docker Compose

Run the command:

docker-compose up -d

This will start:

  • A container with NGINX configured as a reverse proxy, load balancer, and rate limiter.
  • Two containers running Spring Boot, simulating two backend servers.
  • A container with Prometheus.
  • A container with Grafana.

4. Access the Application

Access the application through the URL configured in the container (e.g., http://localhost:8080/hello-world). Access the Grafana dashboard, already consuming data from Prometheus, via http://localhost:3000/.


πŸ“‚ Project Structure

spring_app_server/
β”œβ”€β”€ .mvn/
β”‚   └── [Maven Wrapper files]
β”œβ”€β”€ nginx/
β”‚   └── [Nginx-related configurations]
β”œβ”€β”€ prometheus/
β”‚   └── [Prometheus configuration files]
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main/
β”‚   β”‚   β”œβ”€β”€ java/
β”‚   β”‚   β”‚   └── [Java source code files]
β”‚   β”‚   β”œβ”€β”€ resources/
β”‚   β”‚       └── [Spring Boot resource files like application.properties or application.yml]
β”‚   └── test/
β”‚       └── [Unit tests and integration tests]
β”œβ”€β”€ target/
β”‚   └── [Build output directory]
β”œβ”€β”€ .gitattributes
β”œβ”€β”€ .gitignore
β”œβ”€β”€ docker-compose.yaml
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ HELP.md
β”œβ”€β”€ mvnw
β”œβ”€β”€ mvnw.cmd
β”œβ”€β”€ pom.xml
└── README.md

πŸ› οΈ How to Contribute

  1. Fork the project.
  2. Create a branch for your feature/fix: git checkout -b my-feature.
  3. Make the changes and commit them: git commit -m "My new feature".
  4. Push it to your fork: git push origin my-feature.
  5. Open a Pull Request.

πŸ“„ License

This project is licensed under the MIT License. Feel free to use, modify, and share it.


πŸ§‘β€πŸ’» Author

If you have any questions or suggestions, feel free to open an issue! 😊


πŸ‡§πŸ‡· Nginx Proxy Load Balancer

Este repositório contém uma configuração prÑtica para implementar um balanceador de carga, um rate limiter utilizando o NGINX, além de um circuit breaker e monitoramento com Spring Actuator, Prometheus e Grafana.


πŸš€ Como Usar

1. PrΓ©-requisitos

  • Docker e Docker Compose instalados.
  • Acesso Γ s instΓ’ncias de backend (aplicaçáes que receberΓ£o o trΓ‘fego balanceado).

2. Clonar o RepositΓ³rio

git clone https://github.com/MSpilari/nginx-proxy-lb.git
cd nginx-proxy-lb

3. Subir o Serviço com Docker Compose

Execute o comando:

docker-compose up -d

Isso iniciarΓ‘ um contΓͺiner com o NGINX configurado como proxy reverso, balanceador de carga, rate limiter. Dois contΓͺineres com Sprig boot, rodando uma aplicação simulando dois servidores. Um contΓͺiner com Prometheus. Um contΓͺiner com Grafana.

5. Acessar a Aplicação

Acesse a aplicação atravΓ©s da URL configurada no contΓͺiner (por exemplo, http://localhost:8080/hello-world). Acesso o dashboard do Grafana, jΓ‘ consumindo dados do Prometheus atravΓ©s do URL http://localhost:3000/


πŸ“‚ Estrutura do Projeto

spring_app_server/
β”œβ”€β”€ .mvn/
β”‚   └── [Maven Wrapper files]
β”œβ”€β”€ nginx/
β”‚   └── [Nginx-related configurations]
β”œβ”€β”€ prometheus/
β”‚   └── [Prometheus configuration files]
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main/
β”‚   β”‚   β”œβ”€β”€ java/
β”‚   β”‚   β”‚   └── [Java source code files]
β”‚   β”‚   β”œβ”€β”€ resources/
β”‚   β”‚       └── [Spring Boot resource files like application.properties or application.yml]
β”‚   └── test/
β”‚       └── [Unit tests and integration tests]
β”œβ”€β”€ target/
β”‚   └── [Build output directory]
β”œβ”€β”€ .gitattributes
β”œβ”€β”€ .gitignore
β”œβ”€β”€ docker-compose.yaml
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ HELP.md
β”œβ”€β”€ mvnw
β”œβ”€β”€ mvnw.cmd
β”œβ”€β”€ pom.xml
└── README.md

πŸ› οΈ Como Contribuir

  1. Faça um fork do projeto.
  2. Crie uma branch para a sua funcionalidade/correção: git checkout -b minha-feature.
  3. Realize as alteraçáes e comite: git commit -m "Minha nova feature".
  4. Envie para o seu fork: git push origin minha-feature.
  5. Abra um Pull Request.

πŸ“„ LicenΓ§a

Este projeto estΓ‘ licenciado sob a MIT License. Sinta-se Γ  vontade para usar, modificar e compartilhar.


πŸ§‘β€πŸ’» Autor

Se tiver dúvidas ou sugestáes, sinta-se à vontade para abrir uma issue! 😊