# Pad — nginx reverse proxy # # Usage: # 1. Replace "pad.example.com" with your domain # 2. Update ssl_certificate paths to your TLS certs # 3. Include this file in your nginx config or copy to /etc/nginx/conf.d/ # # Key settings for SSE support: # - proxy_buffering off # - proxy_read_timeout 86400s (24h for long-lived SSE connections) # - proxy_http_version 1.1 with Connection "" upstream pad_backend { server 127.0.0.1:7777; # For Docker: server pad:7777; keepalive 32; } server { listen 80; server_name pad.example.com; return 301 https://$host$request_uri; } server { listen 443 ssl http2; server_name pad.example.com; ssl_certificate /etc/ssl/certs/pad.example.com.pem; ssl_certificate_key /etc/ssl/private/pad.example.com-key.pem; # Modern TLS settings ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384; ssl_prefer_server_ciphers off; # Security headers 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; # Gzip gzip on; gzip_types text/plain application/json text/css application/javascript; # SSE endpoint — requires special proxy settings location /api/v1/events { proxy_pass http://pad_backend; proxy_http_version 1.1; proxy_set_header Connection ""; 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; # Critical for SSE: proxy_buffering off; proxy_cache off; proxy_read_timeout 86400s; proxy_send_timeout 86400s; chunked_transfer_encoding on; } # WebSocket endpoint for Yjs collaborative editing (PLAN-1248). # Differs from SSE in needing the Upgrade/Connection headers # forwarded so nginx negotiates the protocol switch — the default # `/` block clears Connection ("") and would prevent the upgrade. location /api/v1/collab/ { proxy_pass http://pad_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; # Long-lived WebSocket — same 24h budget as SSE so an idle # editor tab does not get cut off mid-session. proxy_buffering off; proxy_cache off; proxy_read_timeout 86400s; proxy_send_timeout 86400s; } # All other routes location / { proxy_pass http://pad_backend; proxy_http_version 1.1; proxy_set_header Connection ""; 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; proxy_read_timeout 60s; # File uploads client_max_body_size 10M; } access_log /var/log/nginx/pad-access.log; error_log /var/log/nginx/pad-error.log; }