#!/usr/bin/env bash set -euo pipefail CONF="infra/gateway/nginx.conf" [[ -f "$CONF" ]] || { echo "[ERR] $CONF not found"; exit 1; } cp "$CONF" "$CONF.bak.$(date +%s)" echo "[OK] backup saved" cat > "$CONF" <<'NGINX' server { listen 80; server_name _; # Docker DNS resolver 127.0.0.11 ipv6=off valid=10s; # Health of gateway itself location = /health { default_type application/json; return 200 '{"status":"ok","gateway":"nginx"}'; } # ===== Unified API Docs (docs aggregator) ===== location = /docs { proxy_pass http://marriage_docs:8000/docs; 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; } location = /redoc { proxy_pass http://marriage_docs:8000/redoc; 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; } location = /openapi.json { proxy_pass http://marriage_docs:8000/openapi.json; 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; } location = /refresh { proxy_pass http://marriage_docs:8000/refresh; 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; } location = /_health { proxy_pass http://marriage_docs:8000/_health; 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; } # ===== Microservices (prefix strip) ===== location /auth/ { rewrite ^/auth/(.*)$ /$1 break; proxy_pass http://marriage_auth:8000; 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 Authorization $http_authorization; } location /profiles/ { rewrite ^/profiles/(.*)$ /$1 break; proxy_pass http://marriage_profiles:8000; 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; } location /match/ { rewrite ^/match/(.*)$ /$1 break; proxy_pass http://marriage_match:8000; 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; } location /chat/ { rewrite ^/chat/(.*)$ /$1 break; proxy_pass http://marriage_chat:8000; 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; } location /payments/ { rewrite ^/payments/(.*)$ /$1 break; proxy_pass http://marriage_payments:8000; 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; } } NGINX echo "[OK] nginx.conf updated" echo "[INFO] restarting gateway..." docker compose restart gateway >/dev/null echo "[INFO] quick checks:" echo -n "gateway: "; curl -s http://localhost:8080/health; echo echo -n "docs/_health:"; curl -s http://localhost:8080/_health; echo for svc in auth profiles match chat payments; do code=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:8080/$svc/health") echo "$svc/health: $code" done