HTTP stream ระยะยาว: timeout และ buffering ของ proxy
SSE/WebSocket stream ขึ้นกับทุก hop ระหว่างไคลเอนต์กับแอป Proxy, CDN และ load balancer อาจตั้ง idle timeout ของตนเอง NGINX proxyreadtimeout มีค่าเริ่มต้น 60 วินาทีระหว่างการอ่าน upstream และ proxy WebSocket ก็ปิดเมื่อไม่มีข้อมูล upstream 60 วินาที ตรวจเวอร์ชันและทุก hop
SSE/WebSocket stream ขึ้นกับทุก hop ระหว่างไคลเอนต์กับแอป Proxy, CDN และ load balancer อาจตั้ง idle timeout ของตนเอง NGINX proxy_read_timeout มีค่าเริ่มต้น 60 วินาทีระหว่างการอ่าน upstream และ proxy WebSocket ก็ปิดเมื่อไม่มีข้อมูล upstream 60 วินาที ตรวจเวอร์ชันและทุก hop
HTTP/1.1 นำ connection กลับมาใช้หลังการแลกเปลี่ยนจบ ส่วน SSE/WebSocket เปิด stream/session ค้างไว้ HTTP/2 multiplex stream จึงอย่านำค่าของ HTTP/1.1 มาใช้ตรง ๆ
location /events {
proxy_pass http://app;
proxy_buffering off;
proxy_read_timeout 90s;
}90 วินาทีเป็นเพียงตัวอย่าง เมื่อปิด buffering NGINX ส่งข้อมูลทันทีที่ได้รับ แอปยังต้องส่ง SSE ถูกต้องและ flush ให้บันทึกว่าใครปิดเมื่อใด ตรวจ idle limit, buffering, compression, flush และ connection ที่เปิดอยู่ SSE comment หรือ WebSocket ping ช่วยรักษาเส้นทางได้ แต่ช่วงเวลาต้องสั้นกว่า timeout ที่สั้นที่สุด Connection ว่างยังใช้ทรัพยากร
แหล่งข้อมูล
[NGINX proxy module](https://nginx.org/en/docs/http/ngx_http_proxy_module.html)
[NGINX WebSocket proxying](https://nginx.org/en/docs/http/websocket.html)
[MDN Using server-sent events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events)