68 lines
2.5 KiB
Nginx Configuration File
68 lines
2.5 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 _;
|
|
# API owns the 10 MiB attachment limit and its JSON error envelope;
|
|
# leave a small header margin so nginx does not generate HTML 413 first.
|
|
client_max_body_size 11m;
|
|
|
|
# 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.
|
|
# A stopped Compose container can black-hole SYNs instead of refusing
|
|
# them. Keep one failed upstream attempt well below the test/client
|
|
# timeout so the healthy replica receives the retry.
|
|
proxy_connect_timeout 500ms;
|
|
# A valid request may stream the permitted 10 MiB through a loaded
|
|
# development Docker host. Connection failure detection stays fast;
|
|
# only an established upload/download gets its bounded 60-second budget.
|
|
proxy_read_timeout 60s;
|
|
proxy_send_timeout 60s;
|
|
|
|
# A refused connection/502 means the selected replica is unavailable and
|
|
# can be retried on its peer. A structured 503 is an application
|
|
# dependency failure (for example PostgreSQL down), not an unhealthy
|
|
# replica: propagating it preserves the API error envelope instead of
|
|
# marking both live peers down and manufacturing an Nginx 502.
|
|
proxy_next_upstream error timeout http_502;
|
|
# Two attempts cover both configured replicas: a request that lands on
|
|
# the stopped instance is retried once on its healthy peer.
|
|
proxy_next_upstream_tries 2;
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|