worker_processes 1; error_log /dev/stderr warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { access_log off; server_tokens off; limit_conn_zone $server_name zone=uploads:64k; # Docker DNS; resolve updates the upstream when replicas get new IPs. resolver 127.0.0.11 valid=1s ipv6=off; resolver_timeout 1s; upstream messenger { zone messenger 64k; # All A records of api participate in the default round-robin balancing. server api:8080 resolve max_fails=1 fail_timeout=2s; } server { listen 8080; server_name messenger; location ~ ^/api/v1/chats/[^/]+/attachments$ { limit_conn uploads 16; client_max_body_size 11m; client_body_buffer_size 64k; client_body_timeout 10s; proxy_request_buffering on; proxy_pass http://messenger; proxy_http_version 1.1; proxy_set_header Host $http_host; proxy_set_header Connection ""; proxy_connect_timeout 1s; proxy_read_timeout 30s; proxy_send_timeout 30s; proxy_next_upstream error timeout http_503; proxy_next_upstream_tries 2; } location / { proxy_pass http://messenger; proxy_http_version 1.1; proxy_set_header Host $http_host; proxy_set_header Connection ""; proxy_connect_timeout 1s; proxy_read_timeout 5s; proxy_send_timeout 5s; # Passive checks. Do NOT enable non_idempotent: an already-sent POST # must not be resent by Nginx after an ambiguous response. proxy_next_upstream error timeout http_503; proxy_next_upstream_tries 2; proxy_next_upstream_timeout 6s; } } }