diff --git a/auto/modules b/auto/modules
index be3561e..55c75ca 100644
--- a/auto/modules
+++ b/auto/modules
@@ -878,6 +878,11 @@ if [ $HTTP = YES ]; then
         ngx_module_link=$HTTP_STUB_STATUS
 
         . auto/module
+
+	if [ $NGX_STAT_STUB_EXTENDED = YES ]; then
+	    have=NGX_STAT_STUB_EXTENDED . auto/have
+	fi
+
     fi
 fi
 
diff --git a/auto/options b/auto/options
index 66b822a..f2a1a88 100644
--- a/auto/options
+++ b/auto/options
@@ -105,6 +105,7 @@ HTTP_UPSTREAM_ZONE=YES
 
 # STUB
 HTTP_STUB_STATUS=NO
+NGX_STAT_STUB_EXTENDED=NO
 
 MAIL=NO
 MAIL_SSL=NO
@@ -279,6 +280,7 @@ $0: warning: the \"--with-ipv6\" option is deprecated"
 
         # STUB
         --with-http_stub_status_module)  HTTP_STUB_STATUS=YES       ;;
+	--with-http_stub_status_extended) NGX_STAT_STUB_EXTENDED=YES ;;
 
         --with-mail)                     MAIL=YES                   ;;
         --with-mail=dynamic)             MAIL=DYNAMIC               ;;
@@ -567,6 +569,7 @@ cat << END
   --with-openssl-opt=OPTIONS         set additional build options for OpenSSL
 
   --with-debug                       enable debug logging
+  --with-http_stub_status_extended   enable extended status codes statistics
 
 END
 
diff --git a/src/event/ngx_event.c b/src/event/ngx_event.c
index 57af813..e702e72 100644
--- a/src/event/ngx_event.c
+++ b/src/event/ngx_event.c
@@ -74,6 +74,13 @@ ngx_atomic_t         *ngx_stat_writing = &ngx_stat_writing0;
 static ngx_atomic_t   ngx_stat_waiting0;
 ngx_atomic_t         *ngx_stat_waiting = &ngx_stat_waiting0;
 
+#if (NGX_STAT_STUB_EXTENDED)
+
+static	ngx_stat_ext_t	ngx_stat_ext0[NGX_STAT_EXT_SIZE];
+ngx_stat_ext_t	*ngx_stat_ext = &ngx_stat_ext0[0];
+
+#endif
+
 #endif
 
 
@@ -497,6 +504,9 @@ ngx_event_module_init(ngx_cycle_t *cycle)
            + cl          /* ngx_stat_writing */
            + cl;         /* ngx_stat_waiting */
 
+#if (NGX_STAT_STUB_EXTENDED)
+    size += sizeof (ngx_stat_ext_t) * NGX_STAT_EXT_SIZE;
+#endif
 #endif
 
     shm.size = size;
@@ -543,6 +553,74 @@ ngx_event_module_init(ngx_cycle_t *cycle)
     ngx_stat_writing = (ngx_atomic_t *) (shared + 8 * cl);
     ngx_stat_waiting = (ngx_atomic_t *) (shared + 9 * cl);
 
+
+#if (NGX_STAT_STUB_EXTENDED)
+    ngx_stat_ext = (ngx_stat_ext_t*) (shared + 10 * cl);
+
+    /*codes we are interested in*/
+    ngx_stat_ext[0].code = 0;		/* default */
+    ngx_stat_ext[1].code = 100;
+    ngx_stat_ext[2].code = 101;
+    ngx_stat_ext[3].code = 102;
+    ngx_stat_ext[4].code = 200;
+    ngx_stat_ext[5].code = 201;
+    ngx_stat_ext[6].code = 202;
+    ngx_stat_ext[7].code = 203;
+    ngx_stat_ext[8].code = 204;
+    ngx_stat_ext[9].code = 205;
+    ngx_stat_ext[10].code = 206;
+    ngx_stat_ext[11].code = 207;
+    ngx_stat_ext[12].code = 300;
+    ngx_stat_ext[13].code = 301;
+    ngx_stat_ext[14].code = 302;
+    ngx_stat_ext[15].code = 303;
+    ngx_stat_ext[16].code = 304;
+    ngx_stat_ext[17].code = 305;
+    ngx_stat_ext[18].code = 307;
+    ngx_stat_ext[19].code = 400;
+    ngx_stat_ext[20].code = 401;
+    ngx_stat_ext[21].code = 402;
+    ngx_stat_ext[22].code = 403;
+    ngx_stat_ext[23].code = 404;
+    ngx_stat_ext[24].code = 405;
+    ngx_stat_ext[25].code = 406;
+    ngx_stat_ext[26].code = 407;
+    ngx_stat_ext[27].code = 408;
+    ngx_stat_ext[28].code = 409;
+    ngx_stat_ext[29].code = 410;
+    ngx_stat_ext[30].code = 411;
+    ngx_stat_ext[31].code = 412;
+    ngx_stat_ext[32].code = 413;
+    ngx_stat_ext[33].code = 414;
+    ngx_stat_ext[34].code = 415;
+    ngx_stat_ext[35].code = 416;
+    ngx_stat_ext[36].code = 417;
+    ngx_stat_ext[37].code = 422;
+    ngx_stat_ext[38].code = 423;
+    ngx_stat_ext[39].code = 424;
+    ngx_stat_ext[40].code = 425;
+    ngx_stat_ext[41].code = 426;
+    ngx_stat_ext[42].code = 428;
+    ngx_stat_ext[43].code = 429;
+    ngx_stat_ext[44].code = 431;
+    ngx_stat_ext[45].code = 434;
+    ngx_stat_ext[46].code = 444;
+    ngx_stat_ext[47].code = 449;
+    ngx_stat_ext[48].code = 451;
+    ngx_stat_ext[49].code = 500;
+    ngx_stat_ext[50].code = 501;
+    ngx_stat_ext[51].code = 502;
+    ngx_stat_ext[52].code = 503;
+    ngx_stat_ext[53].code = 504;
+    ngx_stat_ext[54].code = 505;
+    ngx_stat_ext[55].code = 506;
+    ngx_stat_ext[56].code = 507;
+    ngx_stat_ext[57].code = 508;
+    ngx_stat_ext[58].code = 509;
+    ngx_stat_ext[59].code = 510;
+    ngx_stat_ext[60].code = 511;
+#endif
+
 #endif
 
     return NGX_OK;
diff --git a/src/event/ngx_event.h b/src/event/ngx_event.h
index 053bd16..9503430 100644
--- a/src/event/ngx_event.h
+++ b/src/event/ngx_event.h
@@ -485,6 +485,17 @@ extern ngx_atomic_t  *ngx_stat_reading;
 extern ngx_atomic_t  *ngx_stat_writing;
 extern ngx_atomic_t  *ngx_stat_waiting;
 
+#if (NGX_STAT_STUB_EXTENDED)
+
+typedef struct {
+    ngx_uint_t code;
+    ngx_atomic_t counter;
+} ngx_stat_ext_t;
+
+extern ngx_stat_ext_t *ngx_stat_ext;
+#define	NGX_STAT_EXT_SIZE 61
+
+#endif
 #endif
 
 
diff --git a/src/http/modules/ngx_http_stub_status_module.c b/src/http/modules/ngx_http_stub_status_module.c
index 61199f2..6b60328 100644
--- a/src/http/modules/ngx_http_stub_status_module.c
+++ b/src/http/modules/ngx_http_stub_status_module.c
@@ -1,4 +1,3 @@
-
 /*
  * Copyright (C) Igor Sysoev
  * Copyright (C) Nginx, Inc.
@@ -88,6 +87,7 @@ ngx_http_stub_status_handler(ngx_http_request_t *r)
     ngx_buf_t         *b;
     ngx_chain_t        out;
     ngx_atomic_int_t   ap, hn, ac, rq, rd, wr, wa;
+    int 	       i;
 
     if (!(r->method & (NGX_HTTP_GET|NGX_HTTP_HEAD))) {
         return NGX_HTTP_NOT_ALLOWED;
@@ -118,6 +118,12 @@ ngx_http_stub_status_handler(ngx_http_request_t *r)
            + 6 + 3 * NGX_ATOMIC_T_LEN
            + sizeof("Reading:  Writing:  Waiting:  \n") + 3 * NGX_ATOMIC_T_LEN;
 
+#if (NGX_STAT_STUB_EXTENDED)
+
+    size += NGX_STAT_EXT_SIZE * (sizeof("status_code_: \n") + 4 + NGX_ATOMIC_T_LEN);
+
+#endif
+
     b = ngx_create_temp_buf(r->pool, size);
     if (b == NULL) {
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
@@ -144,6 +150,15 @@ ngx_http_stub_status_handler(ngx_http_request_t *r)
     b->last = ngx_sprintf(b->last, "Reading: %uA Writing: %uA Waiting: %uA \n",
                           rd, wr, wa);
 
+#if (NGX_STAT_STUB_EXTENDED)
+
+    b->last = ngx_sprintf(b->last, "status_code_def: %uA\n", ngx_stat_ext[0].counter);
+    for (i = 1; i < NGX_STAT_EXT_SIZE; i++) {
+      b->last = ngx_sprintf(b->last, "status_code_%uA: %uA\n", ngx_stat_ext[i].code, ngx_stat_ext[i].counter);
+    }
+
+#endif
+
     r->headers_out.status = NGX_HTTP_OK;
     r->headers_out.content_length_n = b->last - b->pos;
 
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index 476f039..8b058fe 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -1,4 +1,3 @@
-
 /*
  * Copyright (C) Igor Sysoev
  * Copyright (C) Nginx, Inc.
@@ -3529,6 +3528,21 @@ ngx_http_log_request(ngx_http_request_t *r)
     for (i = 0; i < n; i++) {
         log_handler[i](r);
     }
+
+#if (NGX_STAT_STUB_EXTENDED)
+
+    if (r == r->main) {
+        for (i = 1; i < NGX_STAT_EXT_SIZE; i++) {
+            if (ngx_stat_ext[i].code == r->headers_out.status) {
+                (void) ngx_atomic_fetch_add(&ngx_stat_ext[i].counter, 1);
+                return;
+            }
+        }
+        (void) ngx_atomic_fetch_add(&ngx_stat_ext[0].counter, 1);
+    }
+
+#endif
+
 }
 
 
