From 23bac3aef1af18f2743b6fc83f6162685950512d Mon Sep 17 00:00:00 2001 From: Are Almaas Date: Wed, 3 Apr 2024 13:45:00 +0200 Subject: [PATCH] chore: add load balancer for web api in docker-compose (#582) 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. --- docker-compose.yml | 12 ++++++++++-- nginx.conf | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 nginx.conf diff --git a/docker-compose.yml b/docker-compose.yml index fa9456f50..2e304d8d4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 @@ -19,7 +29,5 @@ services: - Serilog__MinimumLevel__Default=Debug - ASPNETCORE_URLS=http://+:8080 - ASPNETCORE_ENVIRONMENT=Development - ports: - - "7214:8080" volumes: - ./.aspnet/https:/https diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 000000000..75aaf89bc --- /dev/null +++ b/nginx.conf @@ -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; + } + } +} \ No newline at end of file