Skip to content

Commit

Permalink
fix: use 2 instances with load-balancer
Browse files Browse the repository at this point in the history
  • Loading branch information
jgfranco17 committed Jun 6, 2024
1 parent 8a916ee commit 66cbfd6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
16 changes: 16 additions & 0 deletions config/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
upstream service {
server api:8080;
server api-backup:8081;
}

server {
listen 80;

location / {
proxy_pass http://service;
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 changes: 1 addition & 1 deletion config/prometheus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ global:
scrape_configs:
- job_name: 'api'
static_configs:
- targets: ['api:8080']
- targets: ['api:8080', 'api-backup:8081']
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
version: "3"
services:
# Server instances
api:
build:
context: .
dockerfile: ./docker/api.Dockerfile
ports:
- 8080:8080
container_name: api
api-backup:
build:
context: .
dockerfile: ./docker/api.Dockerfile
ports:
- 8081:8080
container_name: api-backup

# Observability
prometheus:
image: prom/prometheus:latest
container_name: prometheus
Expand All @@ -25,3 +35,15 @@ services:
- GF_SECURITY_ADMIN_PASSWORD=${GRAFANA_PASSWORD}
depends_on:
- prometheus

# Load balancer
nginx:
image: nginx:alpine
container_name: nginx
ports:
- "80:80"
volumes:
- ./config/nginx.conf:/etc/nginx/nginx.conf
depends_on:
- api
- api-backup

0 comments on commit 66cbfd6

Please sign in to comment.