--- src/core/nginx.c.orig	2011-02-28 19:01:31.000000000 +0200
+++ src/core/nginx.c	2011-03-01 13:32:06.000000000 +0200
@@ -199,6 +199,9 @@ int ngx_cdecl
 main(int argc, char *const *argv)
 {
     ngx_int_t         i;
+#if NGX_RLIMIT_NOFILE > 1024
+    struct rlimit     rlmt;
+#endif
     ngx_log_t        *log;
     ngx_cycle_t      *cycle, init_cycle;
     ngx_core_conf_t  *ccf;
@@ -266,6 +269,15 @@ main(int argc, char *const *argv)
 
     /* TODO */ ngx_max_sockets = -1;
 
+#if NGX_RLIMIT_NOFILE > 1024
+    rlmt.rlim_cur = (rlim_t) NGX_RLIMIT_NOFILE;
+    rlmt.rlim_max = (rlim_t) NGX_RLIMIT_NOFILE;
+    if (setrlimit(RLIMIT_NOFILE, &rlmt) == -1) {
+        ngx_log_stderr(0, "setrlimit(RLIMIT_NOFILE, %i) failed",
+                                             NGX_RLIMIT_NOFILE);
+    }
+#endif
+
     ngx_time_init();
 
 #if (NGX_PCRE)