全新安装 nginx 和 ROR 后出现“768 worker_connections are notough”错误

Pur*_*res 3 ubuntu nginx ruby-on-rails thin

我在 Rails 上全新安装了 nginx 和 ruby​​。但在测试时它给了我一个“500 内部服务器错误”。

\n\n

我的应用程序的 error.log 具有以下内容:

\n\n
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"\n2014/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"\n2014/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"\n2014/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"\n
Run Code Online (Sandbox Code Playgroud)\n\n

nginx.conf 有以下内容:

\n\n
user www-data;\nworker_processes 4;\npid /var/run/nginx.pid;\n\nevents {\n    worker_connections 768;\n}\n\nhttp {\n\n    ##\n    # Basic Settings\n    ##\n\n    sendfile on;\n    tcp_nopush on;\n    tcp_nodelay on;\n    keepalive_timeout 65;\n    types_hash_max_size 2048;\n\n    include /etc/nginx/mime.types;\n    default_type application/octet-stream;\n\n    ##\n    # Logging Settings\n    ##\n\n    access_log /var/log/nginx/access.log;\n    error_log /var/log/nginx/error.log;\n\n    ##\n    # Gzip Settings\n    ##\n\n    gzip on;\n    gzip_disable "msie6";\n\n    ##\n    # Virtual Host Configs\n    ##\n\n    include /etc/nginx/conf.d/*.conf;\n    include /etc/nginx/sites-enabled/*;\n\n    fastcgi_buffers 8 16k;\n    fastcgi_buffer_size 32k;\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

myapp.example.com 配置文件:

\n\n
upstream myapp {\n  #server 24.15.27.113;\n  #server 24.15.27.113:3001;\n  #server 24.15.27.113:3002;\n  server 127.0.0.1:3000;\n  server 127.0.0.1:3001;\n  #server 127.0.0.1:3002;\n}\nserver {\n  listen   80;\n  server_name .example.com;\n\n  access_log /var/www/myapp.example.com/log/access.log;\n  error_log  /var/www/myapp.example.com/log/error.log;\n  root     /var/www/myapp.example.com;\n  index    index.html;\n\n  location / {\n    proxy_set_header  X-Real-IP  $remote_addr;\n    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;\n    proxy_set_header  Host $http_host;\n    proxy_redirect  off;\n    try_files /system/maintenance.html $uri $uri/index.html $uri.html @ruby;\n  }\n\n  location @ruby {\n    proxy_pass http://myapp;\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

在上游块内切换回使用 ip 127.0.0.1:3000 和 127.0.0.1:3001 后,服务器生成错误:

\n\n
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\xe2\x80\x9d, host: "24.15.27.113"\n\n2014/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"\n\n2014/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"\n
Run Code Online (Sandbox Code Playgroud)\n\n

更新 05/05/2014:\n我运行以下命令来检查连接:

\n\n
telnet 127.0.0.1 3000 \n
Run Code Online (Sandbox Code Playgroud)\n\n

结果是:

\n\n
Trying 127.0.0.1...\ntelnet: Unable to connect to remote host: Connection refused\n
Run Code Online (Sandbox Code Playgroud)\n\n

我尝试重新启动瘦服务器,但收到错误消息。

\n\n
thin restart -C /etc/thin/myapp.example.com -o 3000\n
Run Code Online (Sandbox Code Playgroud)\n\n

错误:

\n\n
/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)\nfrom /usr/local/rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/daemonizing.rb:111:in `kill\'\nfrom /usr/local/rvm/gems/ruby-2.1.1/gems/thin-1.6.2/lib/thin/controllers/controller.rb:94:in `block in stop\'\n
Run Code Online (Sandbox Code Playgroud)\n

小智 5

老问题,但我有同样的问题,并且接受的答案对我不起作用。

我必须增加worker_connections的数量,如此处所述

/etc/nginx/nginx.conf

events {
    worker_connections 20000;
}
Run Code Online (Sandbox Code Playgroud)