简体   繁体   English

Ubuntu Nginx,Rails和Thin

[英]Ubuntu Nginx, Rails, and Thin

I followed this article to have an Ubuntu Nginx, Rails, and Thin server, but when access the home page I get 500 Internal Server Error and the folloing error log : 我遵循这篇文章有一个Ubuntu Nginx,Rails和Thin服务器,但是当访问主页时,我得到500 Internal Server Error和下面的错误日志:

2012/09/29 18:43:14 [alert] 15917#0: *1013 socket() failed (24: Too many open files) while connecting to upstream, client: 50.57.229.222, server: 50.57.229.222, request: "GET / HTTP/1.0", upstream: "http://50.57.229.222:80/", host: "50.57.229.222"

any idea of what's going on here ? 知道这里发生了什么吗?

/etc/nginx/sites-enabled/gitwatcher.com is here : /etc/nginx/sites-enabled/gitwatcher.com在这里:

upstream gitwatcher {
    server 127.0.0.1:3000;
    server 127.0.0.1:3001;
    server 127.0.0.1:3002;
}
server {
    listen   80;
    server_name  50.57.229.222;

    access_log /var/www/gitwatcher/log/access.log;
    error_log  /var/www/gitwatcher/log/error.log;
    root       /var/www/gitwatcher;
    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://50.57.229.222;
    }
}

I think you have a loop in your nginx configuration. 我认为你的nginx配置有一个循环。 This part says to listen on port 80: 这部分说要听80端口:

server {
    listen   80;
    server_name  50.57.229.222;
    [...]

But then later on, you say to forward requests to the same port and IP address: 但是后来,你说要将请求转发到同一个端口和IP地址:

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

So Nginx decides to forward the request to itself. 所以Nginx决定将请求转发给自己。 It then decides to forward the new request to itself. 然后它决定将新请求转发给自己。 So on and so forth, until you've used all the kernel's file descriptors. 等等,直到你使用了所有内核的文件描述符。

Most likely, you have your thin server running on a different port. 最有可能的是,您的瘦服务器在不同的端口上运行。 You'll need to use that port in the URL in the latter bit of the configuration. 您需要在配置的后一位使用URL中的该端口。

thanks for answering guys, 谢谢你的回答

anyway that was a wrong nginx conf resolved by following this article : http://articles.slicehost.com/2009/3/13/ubuntu-intrepid-nginx-rails-and-thin 无论如何这是一个错误的nginx conf通过以下文章解决: http//articles.slicehost.com/2009/3/13/ubuntu-intrepid-nginx-rails-and-thin

The hint here is in the error message: 此处的提示位于错误消息中:

1013 socket() failed (24: Too many open files) while connecting to upstream

This likely means that you're running into ulimit issues (which is odd at low traffic levels, but very possible, depending on what the app is doing). 这可能意味着您遇到了ulimit问题(在低流量级别时很奇怪,但很可能,这取决于应用程序正在做什么)。

ulimit -n will generally show you your limit on open file handles. ulimit -n通常会显示您对打开文件句柄的限制。 I think this is quite low on OS X, and is usually 1024 on many Linux-flavored systems. 我认为这在OS X上相当低,在许多Linux风格的系统上通常为1024。 You can increase it temporarily on Linux machines with ulimit -n 8192 (or similar), but this won't be persistent across sessions. 您可以在具有ulimit -n 8192 (或类似版本)的Linux计算机上临时增加它,但这不会在会话中保持不变。

To resolve it permanently, you'll want to up your ulimits. 要永久解决它,你需要提升你的ulimits。 Google for "too many open files ulimit" and your operating system to get more information; 谷歌为“太多开放文件ulimit”和你的操作系统获取更多信息; the procedure is slightly different for each operating system. 每个操作系统的过程略有不同。

Redhat-ish systems Redhat-ish系统

Edit /etc/security/limits.conf . 编辑/etc/security/limits.conf At the bottom, add something like: 在底部,添加如下内容:

* 8192 8192

This will set soft and hard ulimits for all users to 8192 open file handles at one time. 这将为所有用户一次设置8192个打开文件句柄的软和硬ulimits。 You'll need to reboot for this to take effect, but you can issue ulimit -n 8192 to immediately apply that limit for that user for that session. 您需要重新启动才能使此功能生效,但您可以发出ulimit -n 8192以立即为该会话的该用户应用该限制。

OS X OS X.

See this answer for a detailed explanation of how to increase file ulimits on OS X platforms. 有关如何在OS X平台上增加文件ulimit的详细说明,请参阅此答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM