客户端浏览器Chrome过早断开连接导致Nginx报400错误的解决办法

什么原因这个哥们已经说了http://my.oschina.net/greki/blog/84314现象如下:

访问access.log日志出现:

192.168.72.1 - - [04/Apr/2013:00:45:28 +0800] "-" 400 0 "-" "-"

错误error.log日志出现:

2013/04/04 00:45:28 [info] 9489#0: *7 client prematurely closed connection while reading client request line, client: 192.168.72.1, server: _

使用patch命令打如下补丁:

diff -ur nginx-0.7.65.orig/src/http/ngx_http_request.c nginx-0.7.65/src/http/ngx_http_request.c
--- nginx-0.7.65.orig/src/http/ngx_http_request.c       2010-02-02 00:06:25.000000000 +0900
+++ nginx-0.7.65/src/http/ngx_http_request.c    2010-02-16 17:12:09.000000000 +0900
@@ -1132,7 +1132,7 @@
         c->error = 1;
         c->log->action = "reading client request headers";
 
-        ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
+        ngx_http_close_request(r, NGX_HTTP_CLIENT_CLOSED_REQUEST_LINE);
         return NGX_ERROR;
     }
 
@@ -2846,7 +2846,9 @@
 
     log->action = "logging request";
 
-    ngx_http_log_request(r);
+    if ( rc != NGX_HTTP_CLIENT_CLOSED_REQUEST_LINE ) {
+        ngx_http_log_request(r);
+    }
 
     log->action = "closing request";
 
diff -ur nginx-0.7.65.orig/src/http/ngx_http_request.h nginx-0.7.65/src/http/ngx_http_request.h
--- nginx-0.7.65.orig/src/http/ngx_http_request.h       2010-02-02 00:54:02.000000000 +0900
+++ nginx-0.7.65/src/http/ngx_http_request.h    2010-02-16 13:25:33.000000000 +0900
@@ -112,6 +112,7 @@
  * own code to log such situation when a client has closed the connection
  * before we even try to send the HTTP header to it
  */
+#define NGX_HTTP_CLIENT_CLOSED_REQUEST_LINE     498
 #define NGX_HTTP_CLIENT_CLOSED_REQUEST     499

将以上patch代码保存为nginx-free-request-400-bad-request.patch并使用以下命令:

[root@nginx-server-study nginx-1.2.8]# patch -p1 < ../nginx-free-request-400-bad-request.patch

原文地址:http://limilic.com/entry/930zlf7u95d876yg 由于nginx版本问题我的patch作了修改,我测试的nginx版本是nginx-1.2.8为目前最新稳定版本

转载于:https://my.oschina.net/springleng/blog/119635

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值