73 lines
2.6 KiB
Nginx Configuration File
73 lines
2.6 KiB
Nginx Configuration File
events {
|
|
worker_connections 1024;
|
|
}
|
|
|
|
http {
|
|
include /etc/nginx/mime.types;
|
|
default_type application/octet-stream;
|
|
|
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
|
'$status $body_bytes_sent "$http_referer" '
|
|
'"$http_user_agent" upstream: $upstream_addr '
|
|
'upstream_status: $upstream_status '
|
|
'rt=$request_time uct="$upstream_connect_time" uht="$upstream_header_time" urt="$upstream_response_time"';
|
|
|
|
access_log /var/log/nginx/access.log main;
|
|
error_log /var/log/nginx/error.log warn;
|
|
|
|
sendfile on;
|
|
keepalive_timeout 65;
|
|
client_max_body_size 15M;
|
|
|
|
# DNS-сервер Docker для динамического обновления IP-адресов контейнеров
|
|
resolver 127.0.0.11 valid=2s ipv6=off;
|
|
|
|
upstream api_backend {
|
|
zone api_backend 64k;
|
|
server api-1:8080 resolve max_fails=1 fail_timeout=2s;
|
|
server api-2:8080 resolve max_fails=1 fail_timeout=2s;
|
|
}
|
|
|
|
server {
|
|
listen 8080;
|
|
server_name _;
|
|
|
|
# Быстрый таймаут обнаружения недоступной реплики
|
|
proxy_connect_timeout 1s;
|
|
proxy_read_timeout 5s;
|
|
proxy_send_timeout 5s;
|
|
|
|
# Базовая политика переключения: безопасно для идемпотентных запросов
|
|
# Неидемпотентные POST не повторяем
|
|
proxy_next_upstream error timeout http_502 http_503;
|
|
proxy_next_upstream_tries 2;
|
|
proxy_next_upstream_timeout 5s;
|
|
|
|
location ~ ^/api/v1/chats/[^/]+/messages$ {
|
|
proxy_pass http://api_backend;
|
|
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 X-Forwarded-Proto $scheme;
|
|
proxy_set_header X-Request-Id $http_x_request_id;
|
|
|
|
proxy_next_upstream error timeout http_502 http_503 non_idempotent;
|
|
proxy_next_upstream_tries 2;
|
|
proxy_next_upstream_timeout 5s;
|
|
}
|
|
|
|
location / {
|
|
proxy_pass http://api_backend;
|
|
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 X-Forwarded-Proto $scheme;
|
|
proxy_set_header X-Request-Id $http_x_request_id;
|
|
}
|
|
}
|
|
}
|