Skip to content

Commit

Permalink
chore: add load balancer for web api in docker-compose (#582)
Browse files Browse the repository at this point in the history
In order to replicate the setup in Container Apps, we add a load
balancer so we can have more than one replica of the web api.
  • Loading branch information
arealmaas authored Apr 3, 2024
1 parent 1ec1f0e commit 23bac3a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
12 changes: 10 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ include:
- docker-compose-no-webapi.yml

services:
dialogporten-webapi-ingress:
image: nginx:1.25.4
ports:
- "7214:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
depends_on:
- dialogporten-webapi
restart: always
dialogporten-webapi:
scale: 2
build:
context: .
dockerfile: src/Digdir.Domain.Dialogporten.WebApi/Dockerfile
Expand All @@ -19,7 +29,5 @@ services:
- Serilog__MinimumLevel__Default=Debug
- ASPNETCORE_URLS=http://+:8080
- ASPNETCORE_ENVIRONMENT=Development
ports:
- "7214:8080"
volumes:
- ./.aspnet/https:/https
21 changes: 21 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# this nginx config is for the load balancer: dialogporten-webapi-ingress in docker-compose.yml
events {}

http {
upstream webapi {
least_conn;
server dialogporten-webapi:8080;
}

server {
listen 80;

location / {
proxy_pass http://webapi;
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;
}
}
}

0 comments on commit 23bac3a

Please sign in to comment.