From 3e825aae59ebdf8bf6a40e3864a284844e378e3a Mon Sep 17 00:00:00 2001 From: kk10 Date: Sat, 17 Oct 2026 23:44:15 +0300 Subject: [PATCH] feat(infra): add nginx load balancer and two api replicas --- deploy/nginx.conf | 19 +++++++++++++++++++ docker-compose.yml | 17 ++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 deploy/nginx.conf diff --git a/deploy/nginx.conf b/deploy/nginx.conf new file mode 100644 index 0000000..7a3088d --- /dev/null +++ b/deploy/nginx.conf @@ -0,0 +1,19 @@ +events {} + +http { + resolver 127.0.0.11 valid=2s ipv6=off; + + server { + listen 8080; + + location / { + set $backend http://api:8080; + proxy_pass $backend; + + proxy_connect_timeout 1s; + proxy_read_timeout 6s; + proxy_next_upstream error timeout http_502 http_503; + proxy_next_upstream_tries 2; + } + } +} diff --git a/docker-compose.yml b/docker-compose.yml index caf3650..5096169 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,14 +3,14 @@ services: build: context: . dockerfile: Dockerfile - image: mtusi-messenger:lab2 - ports: - - "127.0.0.1:8080:${APP_PORT}" + image: mtusi-messenger:lab3 env_file: - .env secrets: - database_url - cache_url + deploy: + replicas: ${API_REPLICAS:-2} depends_on: migrate: condition: service_completed_successfully @@ -56,6 +56,17 @@ services: retries: 10 restart: unless-stopped + load_balancer: + image: nginx:1.31.7-alpine3.24 + ports: + - "127.0.0.1:8080:8080" + volumes: + - ./deploy/nginx.conf:/etc/nginx/nginx.conf:ro + depends_on: + api: + condition: service_healthy + restart: unless-stopped + secrets: postgres_password: file: ./secrets/postgres_password.txt