Rails app running on puma and nginx continues to die every few hours with Bad Gateway

I have a rails app that I just deployed to Digital Ocean and it works on Puma and Nginx.

In the end, everything it returns is a bad gateway, and that is what is in the error.log file

2014/09/09 22:23:06 [error] 5729#0: *3059 connect() to unix:///var/www/mysite/mysite_app.sock failed (111: Connection refused) while connecting to upstream, client: 67.5.19.192, server: mysite.com, request: "GET / HTTP/1.1", upstream: "http://unix:///var/www/mysite/mysite_app.sock:/", host: "mysite.com" 

To fix this, I just restart puma and it seems to work.

How can I debug this to find out why he continues to die?

Here is my nginx configuration:

 upstream mysite { server unix:///var/www/mysite/mysite_app.sock; } server { listen 80; server_name mysite.com; root /var/www/mysite/current/public; client_max_body_size 20M; location / { proxy_pass http://mysite; # match the name of upstream directive which is defined above proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } location ~* ^/assets/ { # Per RFC2616 - 1 year maximum expiry expires 1y; add_header Cache-Control public; # Some browsers still send conditional-GET requests if there a # Last-Modified header or an ETag header even if they haven't # reached the expiry date sent in the Expires header. add_header Last-Modified ""; add_header ETag ""; break; } } 

EDIT

Could this be caused by a lack of memory?

Here is my current state of memory, but since I constantly execute this command every time, the amount of free memory is reduced, and as soon as I restart puma, it jumps back to 150.

 $ free -m total used free shared buffers cached Mem: 490 440 50 0 17 84 -/+ buffers/cache: 338 151 Swap: 0 0 0 
+6
source share
3 answers

It seems that this is actually a problem with ruby ​​2.1 (in particular, I am using 2.1.2) and its garbage collection.

In a google search similar to this, there are many different threads on it http://bit.ly/1s2vBC0

Here is a ruby ​​error in the question: https://bugs.ruby-lang.org/issues/9607

+4
source

Out of memory can be a problem, but it is better to study the puma and rails logs, not just nginx. In the application folder:

 tail -f log/puma* tail -f log/production.log 
+1
source

I had similar problems, but I note that version 2.1.3 is now released and specifically discusses memory issues:

https://www.ruby-lang.org/en/news/2014/09/19/ruby-2-1-3-is-released/

I'll try it now!

0
source

Source: https://habr.com/ru/post/975048/


All Articles