# Rate limit zone for API endpoints — adjust as needed limit_req_zone $binary_remote_addr zone=api_limit:10m rate=30r/s; limit_req_zone $binary_remote_addr zone=auth_limit:10m rate=5r/s; # Upstream pointing to the Swarm nginx container's published port upstream cba_swarm { server 127.0.0.1:8081; keepalive 32; } # HTTP → HTTPS redirect (certbot will modify this once cert is issued) server { listen 80; listen [::]:80; server_name api.viscountmfb.net; # Allow Let's Encrypt challenges location /.well-known/acme-challenge/ { root /var/www/html; } location / { return 301 https://$host$request_uri; } } # HTTPS server server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name api.viscountmfb.net; # SSL hardening ssl_protocols TLSv1.2 TLSv1.3; ssl_prefer_server_ciphers on; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384; ssl_session_timeout 1d; ssl_session_cache shared:SSL:50m; ssl_session_tickets off; ssl_stapling on; ssl_stapling_verify on; # Security headers add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; add_header X-Frame-Options "SAMEORIGIN" always; add_header X-Content-Type-Options "nosniff" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; add_header X-XSS-Protection "1; mode=block" always; # Tighten this CSP based on your actual frontend needs # add_header Content-Security-Policy "default-src 'self'" always; # Logging — separate access and error logs for this site access_log /var/log/nginx/cbaapi.access.log; error_log /var/log/nginx/cbaapi.error.log warn; # Body size for KYC uploads, statement attachments, etc. client_max_body_size 25M; client_body_timeout 60s; client_header_timeout 60s; # Proxy timeouts — adjust if you have long-running endpoints proxy_connect_timeout 30s; proxy_send_timeout 60s; proxy_read_timeout 60s; # Buffering for upstream responses proxy_buffering on; proxy_buffer_size 8k; proxy_buffers 16 8k; # Block common probe paths to reduce log noise location ~* \.(env|git|sql|bak|log|conf)$ { deny all; return 404; } location = /.env { deny all; return 404; } location ~ /\.(?!well-known) { deny all; return 404; } # Stricter rate limit for auth endpoints location ~ ^/(api/(login|register|password)|auth) { limit_req zone=auth_limit burst=10 nodelay; proxy_pass http://cba_swarm; include /etc/nginx/proxy_params_cbaapi; } # General API rate limit location /api/ { limit_req zone=api_limit burst=50 nodelay; proxy_pass http://cba_swarm; include /etc/nginx/proxy_params_cbaapi; } # Everything else location / { proxy_pass http://cba_swarm; include /etc/nginx/proxy_params_cbaapi; } }