Luca G. Soave
Luca G. Soave

Reputation: 12679

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 :

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 :

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;
    }
}

Upvotes: 1

Views: 5222

Answers (3)

Luca G. Soave
Luca G. Soave

Reputation: 12679

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

Upvotes: 1

dpassage
dpassage

Reputation: 5453

I think you have a loop in your nginx configuration. This part says to listen on port 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:

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

So Nginx decides to forward the request to itself. 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.

Upvotes: 2

Chris Heald
Chris Heald

Reputation: 62638

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 -n will generally show you your limit on open file handles. I think this is quite low on OS X, and is usually 1024 on many Linux-flavored systems. You can increase it temporarily on Linux machines with ulimit -n 8192 (or similar), but this won't be persistent across sessions.

To resolve it permanently, you'll want to up your ulimits. Google for "too many open files ulimit" and your operating system to get more information; the procedure is slightly different for each operating system.

Redhat-ish systems

Edit /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. 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.

OS X

See this answer for a detailed explanation of how to increase file ulimits on OS X platforms.

Upvotes: 0

Related Questions