server { listen 443 ssl; server_name whaletownend.xinghangee.icu; ssl_certificate /home/ubuntu/node_test/keys/whaletownend.xinghangee.icu_bundle.crt; ssl_certificate_key /home/ubuntu/node_test/keys/whaletownend.xinghangee.icu.key; client_max_body_size 500M; ssl_session_timeout 5m; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; ssl_prefer_server_ciphers on; add_header X-Content-Type-Options "nosniff" always; add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always; location /socket.io/ { proxy_pass http://127.0.0.1:3000/socket.io/; # 基础反向代理头 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; # Socket.IO/WebSocket 核心配置 proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; # 关键:Socket.IO 需要长超时 + 关闭缓冲 proxy_connect_timeout 75s; proxy_send_timeout 3600s; proxy_read_timeout 3600s; proxy_buffering off; proxy_cache off; # 关闭缓存,避免 Socket.IO 消息延迟 } location / { proxy_pass http://127.0.0.1:3000; # 必须加的 header 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_http_version 1.1; proxy_set_header Connection ""; # 调大超时,避免初始化时被踢掉 proxy_connect_timeout 60s; proxy_send_timeout 60s; proxy_read_timeout 60s; # 建议关闭缓冲,防止页面流式加载时被截断 proxy_buffering off; } }