Ubuntu

全新安裝 nginx 和 ROR 後出現“768 worker_connections are not enough”錯誤

  • April 8, 2016

我在 Rails 上全新安裝了 nginx 和 ruby​​。但它在測試時給了我一個“500 內部伺服器錯誤”。

我的應用程序的 error.log 具有以下內容:

2014/05/01 17:27:15 [alert] 1423#0: *6892 768 worker_connections are not enough while connecting to upstream, client: 24.15.27.113, server: example.com, request: "GET / HTTP/1.0", upstream: "http://24.15.27.113:80/", host: "myapp"
2014/05/01 17:27:16 [alert] 1423#0: *7656 768 worker_connections are not enough while connecting to upstream, client: 24.15.27.113, server: example.com, request: "GET /favicon.ico HTTP/1.0", upstream: "http://24.15.27.113:80/favicon.ico", host: "myapp"
2014/05/01 17:45:50 [alert] 1453#0: *766 768 worker_connections are not enough while connecting to upstream, client: 24.15.27.113, server: example.com, request: "GET / HTTP/1.0", upstream: "http://24.15.27.113:80/", host: "myapp"
2014/05/01 17:45:50 [alert] 1453#0: *1530 768 worker_connections are not enough while connecting to upstream, client: 24.15.27.113, server: example.com, request: "GET /favicon.ico HTTP/1.0", upstream: "http://24.15.27.113:80/favicon.ico", host: "myapp"

nginx.conf 有以下內容:

user www-data;
worker_processes 4;
pid /var/run/nginx.pid;

events {
   worker_connections 768;
}

http {

   ##
   # Basic Settings
   ##

   sendfile on;
   tcp_nopush on;
   tcp_nodelay on;
   keepalive_timeout 65;
   types_hash_max_size 2048;

   include /etc/nginx/mime.types;
   default_type application/octet-stream;

   ##
   # Logging Settings
   ##

   access_log /var/log/nginx/access.log;
   error_log /var/log/nginx/error.log;

   ##
   # Gzip Settings
   ##

   gzip on;
   gzip_disable "msie6";

   ##
   # Virtual Host Configs
   ##

   include /etc/nginx/conf.d/*.conf;
   include /etc/nginx/sites-enabled/*;

   fastcgi_buffers 8 16k;
   fastcgi_buffer_size 32k;
}

myapp.example.com 配置文件:

upstream myapp {
 #server 24.15.27.113;
 #server 24.15.27.113:3001;
 #server 24.15.27.113:3002;
 server 127.0.0.1:3000;
 server 127.0.0.1:3001;
 #server 127.0.0.1:3002;
}
server {
 listen   80;
 server_name .example.com;

 access_log /var/www/myapp.example.com/log/access.log;
 error_log  /var/www/myapp.example.com/log/error.log;
 root     /var/www/myapp.example.com;
 index    index.html;

 location / {
   proxy_set_header  X-Real-IP  $remote_addr;
   proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
   proxy_set_header  Host $http_host;
   proxy_redirect  off;
   try_files /system/maintenance.html $uri $uri/index.html $uri.html @ruby;
 }

 location @ruby {
   proxy_pass http://myapp;
 }
}

在上游塊內切換回使用 ip 127.0.0.1:3000 和 127.0.0.1:3001 後,伺服器生成錯誤:

2014/05/05 10:34:39 [error] 6158#0: *2 no live upstreams while connecting to upstream, client: 52.74.130.210, server: example.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:3001”, host: "24.15.27.113"

2014/05/05 10:34:39 [error] 6158#0: *2 no live upstreams while connecting to upstream, client: 52.74.130.210, server: example.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "24.15.27.113"

2014/05/05 10:34:39 [error] 6158#0: *2 no live upstreams while connecting to upstream, client: 52.74.130.210, server: example.com, request: "GET /favicon.ico HTTP/1.1", upstream: "http://myapp/favicon.ico", host: "24.15.27.113"

2014 年 5 月 5 日更新:我執行以下命令來檢查連接:

telnet 127.0.0.1 3000 

結果是:

Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connection refused

我嘗試重新啟動瘦伺服器,但收到錯誤消息。

thin restart -C /etc/thin/myapp.example.com -o 3000

錯誤:

/usr/local/rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/daemonizing.rb:129:in `send_signal': Can't stop process, no PID found in tmp/pids/thin.3000.pid (Thin::PidFileNotFound)
from /usr/local/rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/daemonizing.rb:111:in `kill'
from /usr/local/rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/controllers/controller.rb:94:in `block in stop'

proxy_set_headerandproxy_redirect指令應該在塊location @ruby中。

對於upstream塊,您應該使用localhostRuby 伺服器的實際埠。如果沒有埠,上游將連接到這個 nginx 伺服器實例,這是一個循環。

老問題,但我有同樣的問題,接受的答案對我不起作用。

我不得不增加worker_connections的數量,如此所述。

/etc/nginx/nginx.conf

events {
   worker_connections 20000;
}

引用自:https://serverfault.com/questions/592619