diff -Nur nginx-1.1.10.orig//src/core/ngx_open_file_cache.c nginx-1.1.10/src/core/ngx_open_file_cache.c
--- nginx-1.1.10.orig//src/core/ngx_open_file_cache.c	2011-09-14 22:28:55.000000000 +0800
+++ nginx-1.1.10/src/core/ngx_open_file_cache.c	2011-12-02 14:50:36.540858923 +0800
@@ -158,6 +158,9 @@
             of->fs_size = ngx_file_fs_size(&fi);
             of->is_dir = ngx_is_dir(&fi);
             of->is_file = ngx_is_file(&fi);
+// twu begin
+            of->is_socket = ngx_is_socket(&fi);
+// twu end
             of->is_link = ngx_is_link(&fi);
             of->is_exec = ngx_is_exec(&fi);
 
@@ -226,6 +229,9 @@
                 of->size = file->size;
 
                 of->is_dir = file->is_dir;
+// twu begin
+                of->is_socket = file->is_socket;
+// twu end
                 of->is_file = file->is_file;
                 of->is_link = file->is_link;
                 of->is_exec = file->is_exec;
@@ -385,6 +391,9 @@
 
         file->is_dir = of->is_dir;
         file->is_file = of->is_file;
+// twu begin
+        file->is_socket = of->is_socket;
+// twu end
         file->is_link = of->is_link;
         file->is_exec = of->is_exec;
         file->is_directio = of->is_directio;
@@ -559,6 +568,9 @@
     of->fs_size = ngx_file_fs_size(&fi);
     of->is_dir = ngx_is_dir(&fi);
     of->is_file = ngx_is_file(&fi);
+// twu begin
+    of->is_socket = ngx_is_socket(&fi);
+// twu end
     of->is_link = ngx_is_link(&fi);
     of->is_exec = ngx_is_exec(&fi);
 
diff -Nur nginx-1.1.10.orig//src/core/ngx_open_file_cache.h nginx-1.1.10/src/core/ngx_open_file_cache.h
--- nginx-1.1.10.orig//src/core/ngx_open_file_cache.h	2011-04-22 18:06:43.000000000 +0800
+++ nginx-1.1.10/src/core/ngx_open_file_cache.h	2011-12-02 14:47:49.366255394 +0800
@@ -42,6 +42,9 @@
     unsigned                 is_link:1;
     unsigned                 is_exec:1;
     unsigned                 is_directio:1;
+// twu begin
+    unsigned                 is_socket:1;
+// twu end
 } ngx_open_file_info_t;
 
 
@@ -73,6 +76,9 @@
     unsigned                 is_exec:1;
     unsigned                 is_directio:1;
 
+// twu begin
+    unsigned                 is_socket:1;
+// twu end
     ngx_event_t             *event;
 };
 
diff -Nur nginx-1.1.10.orig//src/http/modules/ngx_http_rewrite_module.c nginx-1.1.10/src/http/modules/ngx_http_rewrite_module.c
--- nginx-1.1.10.orig//src/http/modules/ngx_http_rewrite_module.c	2011-10-13 20:43:22.000000000 +0800
+++ nginx-1.1.10/src/http/modules/ngx_http_rewrite_module.c	2011-12-02 14:41:18.733259696 +0800
@@ -805,6 +805,13 @@
 
         fop->code = ngx_http_script_file_code;
 
+	// twu begin
+        if (p[1] == 's') {
+            fop->op = ngx_http_script_file_socket;
+            return NGX_CONF_OK;
+        }
+	// twu end
+
         if (p[1] == 'f') {
             fop->op = ngx_http_script_file_plain;
             return NGX_CONF_OK;
@@ -826,6 +833,13 @@
         }
 
         if (p[0] == '!') {
+	    // twu begin
+            if (p[2] == 's') {
+                fop->op = ngx_http_script_file_not_socket;
+                return NGX_CONF_OK;
+            }
+	    // twu end
+
             if (p[2] == 'f') {
                 fop->op = ngx_http_script_file_not_plain;
                 return NGX_CONF_OK;
diff -Nur nginx-1.1.10.orig//src/http/ngx_http_script.c nginx-1.1.10/src/http/ngx_http_script.c
--- nginx-1.1.10.orig//src/http/ngx_http_script.c	2011-10-12 21:28:03.000000000 +0800
+++ nginx-1.1.10/src/http/ngx_http_script.c	2011-12-02 14:46:36.795701850 +0800
@@ -1518,12 +1518,18 @@
 
         switch (code->op) {
 
+// twu begin
+        case ngx_http_script_file_socket:
+// twu end
         case ngx_http_script_file_plain:
         case ngx_http_script_file_dir:
         case ngx_http_script_file_exists:
         case ngx_http_script_file_exec:
              goto false_value;
 
+// twu begin
+        case ngx_http_script_file_not_socket:
+// twu end
         case ngx_http_script_file_not_plain:
         case ngx_http_script_file_not_dir:
         case ngx_http_script_file_not_exists:
@@ -1535,6 +1541,20 @@
     }
 
     switch (code->op) {
+    // twu begin
+    case ngx_http_script_file_socket:
+        if (of.is_socket) {
+             goto true_value;
+        }
+        goto false_value;
+
+    case ngx_http_script_file_not_socket:
+        if (of.is_socket) {
+            goto false_value;
+        }
+        goto true_value;
+
+    // twu end
     case ngx_http_script_file_plain:
         if (of.is_file) {
              goto true_value;
diff -Nur nginx-1.1.10.orig//src/http/ngx_http_script.h nginx-1.1.10/src/http/ngx_http_script.h
--- nginx-1.1.10.orig//src/http/ngx_http_script.h	2010-09-13 20:44:43.000000000 +0800
+++ nginx-1.1.10/src/http/ngx_http_script.h	2011-12-02 14:43:40.627685828 +0800
@@ -172,6 +172,11 @@
     ngx_http_script_file_not_exists,
     ngx_http_script_file_exec,
     ngx_http_script_file_not_exec
+    // twu begin
+    ,
+    ngx_http_script_file_socket,
+    ngx_http_script_file_not_socket
+    // twu end
 } ngx_http_script_file_op_e;
 
 
diff -Nur nginx-1.1.10.orig//src/os/unix/ngx_files.h nginx-1.1.10/src/os/unix/ngx_files.h
--- nginx-1.1.10.orig//src/os/unix/ngx_files.h	2011-11-14 22:59:00.000000000 +0800
+++ nginx-1.1.10/src/os/unix/ngx_files.h	2011-12-02 14:52:39.118452673 +0800
@@ -153,6 +153,9 @@
 #define ngx_link_info_n          "lstat()"
 
 #define ngx_is_dir(sb)           (S_ISDIR((sb)->st_mode))
+// twu begin
+#define ngx_is_socket(sb)        (S_ISSOCK((sb)->st_mode))
+// twu end
 #define ngx_is_file(sb)          (S_ISREG((sb)->st_mode))
 #define ngx_is_link(sb)          (S_ISLNK((sb)->st_mode))
 #define ngx_is_exec(sb)          (((sb)->st_mode & S_IXUSR) == S_IXUSR)
@@ -239,6 +242,10 @@
 
 #define ngx_de_is_dir(dir)                                                   \
     (((dir)->type) ? ((dir)->type == DT_DIR) : (S_ISDIR((dir)->info.st_mode)))
+// twu begin
+#define ngx_de_is_socket(dir)                                                  \
+    (((dir)->type) ? ((dir)->type == DT_SOCK) : (S_ISSOCK((dir)->info.st_mode)))
+// twu end
 #define ngx_de_is_file(dir)                                                  \
     (((dir)->type) ? ((dir)->type == DT_REG) : (S_ISREG((dir)->info.st_mode)))
 #define ngx_de_is_link(dir)                                                  \
@@ -247,6 +254,9 @@
 #else
 
 #define ngx_de_is_dir(dir)       (S_ISDIR((dir)->info.st_mode))
+// twu begin
+#define ngx_de_is_socket(dir)    (S_ISSOCK((dir)->info.st_mode))
+// twu end
 #define ngx_de_is_file(dir)      (S_ISREG((dir)->info.st_mode))
 #define ngx_de_is_link(dir)      (S_ISLNK((dir)->info.st_mode))
 
