Closed GabrielMelhem closed 1 day ago
Implemented Load Balancing by using Nginx
steps:
1- Define the Load Balancer Configuration
http {
upstream urlshortener_backend {
least_conn; # Load balance based on the least number of connections
server localhost:8080;
server localhost:8082;
server localhost:8083;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://urlshortener_backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
2- define multiple instances of urlshortener service in Docker Compose
urlshortener1: build: . container_name: urlshortener1_container image: urshorterer:latest ports:
postgres environment: SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/urlshortener_dev SPRING_DATASOURCE_USERNAME: postgres SPRING_DATASOURCE_PASSWORD: 1234 SPRING_PROFILES_ACTIVE: dev
urlshortener2: build: . container_name: urlshortener2_container image: urshorterer:latest ports:
postgres environment: SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/urlshortener_dev SPRING_DATASOURCE_USERNAME: postgres SPRING_DATASOURCE_PASSWORD: 1234 SPRING_PROFILES_ACTIVE: dev
urlshortener3: build: . container_name: urlshortener3_container image: urshorterer:latest ports:
Acceptance Criteria (ACs):