<br>The documentation for the mail proxy module state the &quot;so_keepalive&quot; variable can be used to toggle keepalive functionality to the backend server.<br><br>The actual code though uses this configuration variable to drive keepalive functionality on the client side connection though. Below is a short patch which changes the keepalive functionality to the backend server.<br>
<br>--- ngx_mail_proxy_module.c.orig        2009-11-02 10:14:17.000000000 -0500<br>+++ ngx_mail_proxy_module.c     2010-03-01 14:09:20.866649958 -0500<br>@@ -120,18 +120,6 @@<br> <br>     cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);<br>
 <br>-    if (cscf-&gt;so_keepalive) {<br>-        keepalive = 1;<br>-<br>-        if (setsockopt(s-&gt;connection-&gt;fd, SOL_SOCKET, SO_KEEPALIVE,<br>-                       (const void *) &amp;keepalive, sizeof(int))<br>
-                == -1)<br>-        {<br>-            ngx_log_error(NGX_LOG_ALERT, s-&gt;connection-&gt;log, ngx_socket_errno,<br>-                          &quot;setsockopt(SO_KEEPALIVE) failed&quot;);<br>-        }<br>-    }<br>
-<br>     p = ngx_pcalloc(s-&gt;connection-&gt;pool, sizeof(ngx_mail_proxy_ctx_t));<br>     if (p == NULL) {<br>         ngx_mail_session_internal_server_error(s);<br>@@ -154,6 +142,18 @@<br>         return;<br>     }<br>
 <br>+    if (cscf-&gt;so_keepalive) {<br>+        keepalive = 1;<br>+<br>+        if (setsockopt(s-&gt;proxy-&gt;upstream.connection-&gt;fd, SOL_SOCKET, SO_KEEPALIVE,<br>+                       (const void *) &amp;keepalive, sizeof(int))<br>
+                == -1)<br>+        {<br>+            ngx_log_error(NGX_LOG_ALERT, s-&gt;connection-&gt;log, ngx_socket_errno,<br>+                          &quot;setsockopt(SO_KEEPALIVE) failed&quot;);<br>+        }<br>+    }<br>
+<br>     ngx_add_timer(p-&gt;upstream.connection-&gt;read, cscf-&gt;timeout);<br> <br>     p-&gt;upstream.connection-&gt;data = s;<br><br clear="all"><br>-- <br>Sridhar<br>