# Nginx reverse proxy for bal-server # Place this file in /etc/nginx/sites-available/ and symlink to sites-enabled # Replace BAL_DOMAIN with your actual domain # HTTP redirect to HTTPS server { listen 80; listen [::]:80; server_name BAL_DOMAIN; return 301 https://$server_name$request_uri; } # HTTPS proxy to bal-server (localhost only) server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name BAL_DOMAIN; # Let's Encrypt certificates (managed by certbot) ssl_certificate /etc/letsencrypt/live/BAL_DOMAIN/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/BAL_DOMAIN/privkey.pem; # Security headers (no HSTS to avoid preloading issues) 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; # Body size limit — must match Actix PayloadConfig (default 1 MB) client_max_body_size 1m; # Rate limiting zone (requires `limit_req_zone` in nginx.conf) # limit_req zone=bal burst=20 nodelay; # limit_conn addr 10; # Proxy to bal-server on localhost location / { proxy_pass http://127.0.0.1:9137; 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 5s; proxy_send_timeout 10s; proxy_read_timeout 30s; } # Optional: serve public_key.pem directly from Nginx (faster) # location /.pub_key.pem { # alias /var/bal/public_key.pem; # add_header Content-Type text/plain; # } }