I have nodejs app that sending > 800 mongodb documents on client startup (execute only when a client access my app for the first time).
Nginx as reverse proxy in front of node server.
App server spec
- Digital Ocean
- CentOS 7.2
- 2GB Ram
- 2CPU
MongoDB server spec
- Digital Ocean
- Ubuntu 14.04
- 512 RAM
- 1 CPU
nginx -v // nginx version: nginx/1.8.1
nginx config
user nginx;
worker_processes 2;
worker_rlimit_nofile 100480;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
index index.html index.htm;
server {
server_name 128.199.139.xxx;
root /var/www/myapp/bundle/public;
module_app_type node;
module_startup_file main.js;
module_env_var MONGO_URL mongodb://{username}:{password}@128.199.139.xxx:27017/;
module_env_var ROOT_URL http://128.199.139.xxx;
location / {
proxy_pass http://128.199.139.xxx;
proxy_http_version 1.1;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#proxy_set_header X-Real-IP $remote_addr;
# pass the host header - http://wiki.nginx.org/HttpProxyModule#proxy_pass
#proxy_set_header Host $host;
# WebSocket proxying - from http://nginx.org/en/docs/http/websocket.html
proxy_set_header Upgrade "upgrade";
proxy_set_header Connection $http_upgrade;
#add_header 'Access-Control-Allow-Origin' '*';
}
}
server {
listen 80 default_server;
server_name localhost;
root /usr/share/nginx/html;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
# redirect server error pages to the static page /40x.html
#
error_page 404 /404.html;
location = /40x.html {
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
}
Error Log
Below error log:
2016/03/17 09:46:00 [crit] 10295#0: accept4() failed (24: Too many open files)
2016/03/17 09:46:01 [crit] 10295#0: accept4() failed (24: Too many open files)
2016/03/17 09:46:01 [crit] 10295#0: accept4() failed (24: Too many open files)
.....many duplicate error as above
2016/03/17 09:47:35 [error] 10295#0: *4064 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 128.199.139.160, server: 128.199.139.1$
2016/03/17 09:47:35 [alert] 10295#0: accept4() failed (9: Bad file descriptor)
[ 2016-03-17 09:53:47.8144 10403/7f2833c9a700 age/Ust/UstRouterMain.cpp:422 ]: Signal received. Gracefully shutting down... (send signal 2 more time(s) to force shutdown)
[ 2016-03-17 09:53:47.8145 10403/7f2839500880 age/Ust/UstRouterMain.cpp:492 ]: Received command to shutdown gracefully. Waiting until all clients have disconnected...
[ 2016-03-17 09:53:47.8146 10403/7f2833c9a700 Ser/Server.h:464 ]: [UstRouter] Shutdown finished
2016/03/17 09:54:11 [alert] 10549#0: 1024 worker_connections are not enough
2016/03/17 09:54:11 [error] 10549#0: *1021 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 128.199.139.160, server: 128.199.139.1$
2016/03/17 09:54:12 [alert] 10549#0: 1024 worker_connections are not enough
2016/03/17 09:54:12 [error] 10549#0: *2043 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 128.199.139.160, server: 128.199.139.1$
2016/03/17 11:43:20 [alert] 10549#0: 1024 worker_connections are not enough
2016/03/17 11:43:20 [error] 10549#0: *3069 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 128.199.139.160, server: 128.199.139.1$
2016/03/17 13:49:54 [error] 10549#0: *3071 open() "/usr/share/nginx/html/robots.txt" failed (2: No such file or directory), client: 180.97.106.xx, server: localhost, request: "GET
Appreciated for any help or clue
PROBLEM
The problem is I'm getting following error according to above setup:
- Too many open files
- worker_connections are not enough
- (104: Connection reset by peer) while reading response header from upstream
How to solve this issue? Thanks