forked from mtusi2026/mtusi2026lab6
45 lines
1.8 KiB
Nginx Configuration File
45 lines
1.8 KiB
Nginx Configuration File
worker_processes auto;
|
||
events { worker_connections 1024; }
|
||
|
||
http {
|
||
# Nginx OSS резолвит DNS в upstream один раз при старте.
|
||
# Поэтому перечисляем обе реплики явно по DNS-именам контейнеров Compose.
|
||
upstream api_pool {
|
||
server messenger-lab6-api-1:8080 max_fails=1 fail_timeout=5s;
|
||
server messenger-lab6-api-2:8080 max_fails=1 fail_timeout=5s;
|
||
keepalive 16;
|
||
}
|
||
|
||
server {
|
||
listen 80;
|
||
|
||
location / {
|
||
proxy_pass http://api_pool;
|
||
proxy_http_version 1.1;
|
||
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 Connection "";
|
||
|
||
# Retry только на connection errors/timeouts (backend не ответил).
|
||
proxy_next_upstream error timeout;
|
||
proxy_next_upstream_tries 2;
|
||
|
||
proxy_connect_timeout 2s;
|
||
# 15s вместо 60s: мёртвый backend помечается быстрее,
|
||
# failover укладывается в 10-секундный бюджет.
|
||
proxy_send_timeout 15s;
|
||
proxy_read_timeout 15s;
|
||
|
||
# 11m, а не 10m: пропускаем до backend, чтобы он сам вернул 413
|
||
# с X-Request-Id и телом ошибки. Верхний лимит 10 MiB — в приложении.
|
||
client_max_body_size 11m;
|
||
|
||
# ВАЖНО: on, а не off. С off nginx стримит тело в backend
|
||
# и не может повторить POST на живую реплику, если backend умер
|
||
# посреди запроса.
|
||
proxy_request_buffering on;
|
||
}
|
||
}
|
||
}
|