nginxでクライアントが接続を切った場合の400 bad requestの件

★以下のpatchでは解決しないみたい。=> patch変更して対応。

ECONNRESETでクライアントとの接続が切れることはまぁまぁ、あることだということがわかって来た。


nginxでクライアントがリクエストを送る前に接続を切ると、ログに

127.0.0.1 - - [16/Feb/2010:11:30:44 +0900] "-" 400 0 "-" "-"

な感じのものが残り、エラーログにも残るんだけど。

2010/02/16 11:21:52 [info] 29643#0: *1 client closed prematurely connection while reading client request line, client: 127.0.0.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 ( error != 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
  
created by blog.nomadscafe.jp

コメント

コメントはありません

コメントを投稿

コメントを投稿するにはログインが必要です