# ============================================================ # Spanglish Community - Backend API # api.spanglishcommunity.com # ============================================================ server { listen 80; server_name api.spanglishcommunity.com; # ACME location /.well-known/acme-challenge/ { root /var/www/html; } # Force HTTPS location / { return 301 https://api.spanglishcommunity.com$request_uri; } } server { listen 443 ssl; http2 on; server_name api.spanglishcommunity.com; # SSL ssl_certificate /etc/letsencrypt/live/spanglishcommunity.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/spanglishcommunity.com/privkey.pem; include /etc/letsencrypt/options-ssl-nginx.conf; ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # Security (API) add_header X-Frame-Options "DENY" always; add_header X-Content-Type-Options "nosniff" always; # Logs access_log /var/log/nginx/spanglish_api_access.log; error_log /var/log/nginx/spanglish_api_error.log; location / { limit_req zone=spanglish_api_limit burst=50 nodelay; # CORS Configuration set $cors_origin ""; if ($http_origin ~* "^https://(www\.)?spanglishcommunity\.com$") { set $cors_origin $http_origin; } # Handle preflight OPTIONS requests if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin' $cors_origin always; add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, PATCH, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always; add_header 'Access-Control-Allow-Credentials' 'true' always; add_header 'Access-Control-Max-Age' 86400 always; add_header 'Content-Type' 'text/plain; charset=utf-8'; add_header 'Content-Length' 0; return 204; } # Add CORS headers to all responses add_header 'Access-Control-Allow-Origin' $cors_origin always; add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, PATCH, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,Authorization' always; add_header 'Access-Control-Allow-Credentials' 'true' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; proxy_pass http://spanglish_backend; 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_read_timeout 300s; proxy_connect_timeout 300s; } }