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.
To enable HTTPS, follow these steps to create a self-signed SSL certificate:
-
Open a terminal and navigate to the
docker/ssl/
directory. -
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.
Start the application using Docker Compose:
docker-compose up -d
Once the containers are running, open your browser or API tool (e.g., Postman) and access:
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.