61 lines
2.3 KiB
Nginx Configuration File
61 lines
2.3 KiB
Nginx Configuration File
upstream api_backend {
|
|
# Балансировка между несколькими API-репликами с активными проверками.
|
|
# max_fails и fail_timeout обеспечивают пассивную проверку здоровья.
|
|
server api-1:8080 max_fails=3 fail_timeout=10s;
|
|
server api-2:8080 max_fails=3 fail_timeout=10s;
|
|
|
|
# Параметры балансировки для лучшей отказоустойчивости.
|
|
keepalive 32;
|
|
}
|
|
|
|
server {
|
|
listen 8080;
|
|
server_name localhost;
|
|
|
|
# Таймауты для предотвращения зависаний.
|
|
proxy_connect_timeout 5s;
|
|
proxy_send_timeout 60s;
|
|
proxy_read_timeout 60s;
|
|
|
|
# Передача заголовков клиента в backend.
|
|
proxy_set_header Host $http_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;
|
|
|
|
# Основной location для API.
|
|
location / {
|
|
proxy_pass http://api_backend;
|
|
proxy_set_header Host $http_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;
|
|
|
|
# Повторная попытка на другой реплике при ошибке.
|
|
proxy_next_upstream error timeout http_503 non_idempotent;
|
|
proxy_next_upstream_tries 2;
|
|
proxy_next_upstream_timeout 10s;
|
|
|
|
# Поддержка keepalive соединений.
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Connection "";
|
|
}
|
|
|
|
# Health check endpoint для Nginx.
|
|
location /health/live {
|
|
proxy_pass http://api_backend/health/live;
|
|
proxy_set_header Host $http_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;
|
|
}
|
|
|
|
location /health/ready {
|
|
proxy_pass http://api_backend/health/ready;
|
|
proxy_set_header Host $http_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;
|
|
}
|
|
}
|