Отправка множества записей при запуске клиента. Nginx 502 плохой шлюз, слишком много открытых файлов
У меня есть приложение nodejs, которое отправляет> 800 документов mongodb при запуске клиента (выполняется только при первом обращении клиента к моему приложению).
Nginx в качестве обратного прокси-сервера перед сервером узла.
Спецификация сервера приложений
- Цифровой океан
- CentOS 7.2
- 2 ГБ оперативной памяти
- 2CPU
Спецификация сервера MongoDB
- Цифровой океан
- Ubuntu 14.04
- 512 ОЗУ
- 1 процессор
nginx -v // версия nginx: nginx/1.8.1
Конфигурация nginx
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 {
}
}
}
Журнал ошибок
Ниже журнал ошибок:
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
Ценим за любую помощь или подсказку
ПРОБЛЕМА
Проблема в том, что я получаю следующую ошибку в соответствии с приведенной выше настройкой:
- Слишком много открытых файлов
- Недостаточно рабочих соединений
- (104: сброс соединения по одноранговому узлу) при чтении заголовка ответа из восходящего потока
Как решить эту проблему? Спасибо
1 ответ
Что ж, похоже, что немного погуглил, типа "рабочих соединений недостаточно" или "nginx слишком много открытых файлов" уже дает некоторые подсказки, например, может быть проксирование к порту 80 (на общедоступном IP-адресе):
proxy_pass http://128.199.139.xxx;
приводит к циклу (отсюда "слишком много открытых файлов" и "1024 рабочих недостаточно").
Может быть, вы должны попробовать эти подсказки и сказать, если они не решили вашу проблему.
https://stackoverflow.com/questions/28265717/worker-connections-are-not-enough
Слишком много открытых файлов с nginx, не могу увеличить лимит
http://www.cyberciti.biz/faq/linux-unix-nginx-too-many-open-files/
https://anothersysadmin.wordpress.com/2013/08/09/nginx-and-the-too-many-open-files-limit/