如何使用 FastCGI 应用程序检测 nginx 中的客户端断开连接(HTTP 499)

How to detect Client disconnect (HTTP 499) in nginx with a FastCGI App

Nginx 成功检测到客户端在发送响应之前断开连接,并在访问日志中记录为代码 499 但是我的 FastCGI(在 C 中)应用程序在响应期间没有给出任何错误。

有没有办法在 nginx 后面的 FastCGI(C 语言)中检测客户端超时?

好的。我找到了答案。

有一个 link 要求在写入流后使用 FCGX_GetError() 来检测错误。

问题是IO被缓冲了,所以没有报错。

所以我使用了 FCGX_FFlush(request.out) 它就像一个魅力,当客户端超时时给出 -1。

注意:nginx 检测到此客户端断开连接并在访问日志中输入代码 499。