什么原因这个哥们已经说了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为目前最新稳定版本