# SnowWorld Narrowcasting System - Nginx Configuration events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; # Logging access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; # Gzip compression gzip on; gzip_vary on; gzip_min_length 1024; gzip_types text/plain text/css text/xml text/javascript application/javascript application/xml+rss application/json; # Rate limiting limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s; limit_req_zone $binary_remote_addr zone=upload:10m rate=2r/s; # Upstream backend upstream backend { server snowworld-narrowcasting:3000; keepalive 32; } # HTTP redirect to HTTPS server { listen 80; server_name _; return 301 https://$server_name$request_uri; } # HTTPS server server { listen 443 ssl http2; server_name _; # SSL configuration ssl_certificate /etc/nginx/ssl/cert.pem; ssl_certificate_key /etc/nginx/ssl/key.pem; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384; ssl_prefer_server_ciphers off; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; # Security headers add_header X-Frame-Options DENY; add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; # Serve static files for admin dashboard location /admin { alias /usr/share/nginx/html/admin; try_files $uri $uri/ /admin/index.html; expires 1h; add_header Cache-Control "public, immutable"; } # Serve static files for client display location /client { alias /usr/share/nginx/html/client; try_files $uri $uri/ /client/index.html; expires 1h; add_header Cache-Control "public, immutable"; } # Serve uploaded files location /uploads { alias /app/public/uploads; expires 1d; add_header Cache-Control "public, immutable"; # Security headers for uploaded content add_header X-Content-Type-Options nosniff; add_header X-Frame-Options DENY; } # API endpoints with rate limiting location /api { limit_req zone=api burst=20 nodelay; proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; 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_cache_bypass $http_upgrade; proxy_buffering off; proxy_read_timeout 300s; proxy_connect_timeout 75s; } # WebSocket support location /socket.io { proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; 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_buffering off; } # Default location location / { return 301 /client/index.html; } } }