--- src/core/nginx.c.orig 2011-02-28 19:01:31.000000000 +0200 +++ src/core/nginx.c 2011-02-28 19:29:38.000000000 +0200 @@ -8,6 +8,7 @@ #include #include +#define NGX_DEFAULT_RLIMIT_NOFILE (40 * 1024) static ngx_int_t ngx_add_inherited_sockets(ngx_cycle_t *cycle); static ngx_int_t ngx_get_options(int argc, char *const *argv); @@ -199,6 +200,7 @@ main(int argc, char *const *argv) { ngx_int_t i; + struct rlimit rlmt; ngx_log_t *log; ngx_cycle_t *cycle, init_cycle; ngx_core_conf_t *ccf; @@ -266,6 +268,13 @@ /* TODO */ ngx_max_sockets = -1; + rlmt.rlim_cur = (rlim_t) NGX_DEFAULT_RLIMIT_NOFILE; + rlmt.rlim_max = (rlim_t) NGX_DEFAULT_RLIMIT_NOFILE; + if (setrlimit(RLIMIT_NOFILE, &rlmt) == -1) { + ngx_log_stderr(0, "setrlimit(RLIMIT_NOFILE, %i) failed", + NGX_DEFAULT_RLIMIT_NOFILE); + } + ngx_time_init(); #if (NGX_PCRE)