Skip to content

Joao-Lucas-de-Oliveira-Lima/spring-nginx-loadbalancer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nginx as Load Balancer and Reverse Proxy for a Spring API

Java Spring Nginx Docker


Table of Contents


About

This project demonstrates how to configure Nginx as a load balancer and reverse proxy for a Spring Boot API running across three instances. It also covers how to enable HTTPS communication using a self-signed SSL certificate.


Getting Started

Prerequisites


Generating SSL/TLS Certificate

To enable HTTPS, follow these steps to create a self-signed SSL certificate:

Steps

  1. Open a terminal and navigate to the docker/ssl/ directory.

  2. Run the following command:

    openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout nginx-selfsigned.key -out nginx-selfsigned.crt

This will generate a public/private key pair to establish secure HTTPS communication.

The certificate files will be automatically mounted into the Nginx container and referenced within the Nginx configuration file.


Running the Containers

Start the application using Docker Compose:

docker-compose up -d

Usage

Once the containers are running, open your browser or API tool (e.g., Postman) and access:

🔗 https://localhost:3443/api/greetings

How It Works

  • localhost:3443 is mapped to the Nginx container.
  • Docker maps this external port to internal port 443 (HTTPS).
  • Nginx acts as a reverse proxy and load balancer, distributing requests among three Spring Boot instances.
  • The /api/greetings endpoint returns a message indicating which instance handled the request.

📌 Note: Since the certificate is self-signed, your browser may display a security warning. You can proceed by accepting the risk manually.


About

Nginx load balancer and HTTPS reverse proxy for Spring Boot with Docker.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published