server {
  listen 20015;
  server_name _;

  resolver 127.0.0.11 valid=5s ipv6=off;

  location / {
    auth_request /backend-health;
    error_page 500 502 503 504 =503 /maintenance.html;

    set $frontend_upstream http://frontend:20015;

    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_connect_timeout 1s;
    proxy_send_timeout 30s;
    proxy_read_timeout 30s;
    proxy_intercept_errors on;

    proxy_pass $frontend_upstream;
  }

  location = /backend-health {
    internal;
    set $backend_upstream http://backend:3001/health;

    proxy_pass_request_body off;
    proxy_set_header Content-Length "";
    proxy_connect_timeout 1s;
    proxy_read_timeout 1s;

    proxy_pass $backend_upstream;
  }

  location = /maintenance.html {
    internal;
    root /usr/share/nginx/html;
    add_header Cache-Control "no-store" always;
    add_header Retry-After "300" always;
  }
}
