- 2 API-реплики (api-1, api-2) с уникальным INSTANCE_ID - Nginx load balancer с health-check и failover - PostgreSQL источник истины, Valkey кэш сессий - Idempotency-Key в заголовке, replay возвращает исходное сообщение - X-Instance-Id в каждом ответе для идентификации реплики - /version и /info эндпоинты - Housekeeping-loop для очистки истёкших сессий и ключей - stop-one.sh/cmd для failover-теста, restart.sh/cmd для persistence - Исправлены импорты config/models/api/store/sessions - Добавлены миграции 004 (idempotency), 005 (indexes), 006 (message_id) - Отчёт с доказательствами критериев уровня 3 и 4 - Все тесты проходят: smoke, 26 student tests, failover, persistence, degradation
53 lines
1.4 KiB
Nginx Configuration File
53 lines
1.4 KiB
Nginx Configuration File
events {
|
|
worker_connections 1024;
|
|
}
|
|
|
|
http {
|
|
include /etc/nginx/mime.types;
|
|
default_type application/octet-stream;
|
|
|
|
# Upstream group: both API replicas. Health-checked by Nginx so a stopped
|
|
# replica is taken out of rotation automatically (max_fails + fail_timeout).
|
|
upstream api {
|
|
server api-1:8080 max_fails=3 fail_timeout=10s;
|
|
server api-2:8080 max_fails=3 fail_timeout=10s;
|
|
}
|
|
|
|
server {
|
|
listen 8080;
|
|
server_name _;
|
|
|
|
# Keep the instance header so clients can see which replica answered.
|
|
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;
|
|
|
|
# Never wait forever on a dead replica.
|
|
proxy_connect_timeout 2s;
|
|
proxy_read_timeout 10s;
|
|
proxy_send_timeout 10s;
|
|
|
|
# Redirect on 502/503 to the next available replica once, then give up.
|
|
proxy_next_upstream error timeout http_502 http_503;
|
|
proxy_next_upstream_tries 1;
|
|
|
|
location / {
|
|
proxy_pass http://api;
|
|
}
|
|
|
|
location /health/ready {
|
|
# Readiness is checked by Compose on the LB itself; forward to api.
|
|
proxy_pass http://api;
|
|
}
|
|
|
|
location /version {
|
|
proxy_pass http://api;
|
|
}
|
|
|
|
location /info {
|
|
proxy_pass http://api;
|
|
}
|
|
}
|
|
}
|