1

I'm trying to diagnose server timeouts on ubuntu 16.04. I've seen this site http://blogs.candoerz.com/question/161218/cannot-figure-out-nginx--puma-timeout-110-connection-timed-out.aspx and suggestions given there didn't work. However the site does not address the problem I'm concerned with:

one part of the error log looks particularly strange

upstream: "http://unix:///home/chris/Rails/chrisbim2ree/shared/tmp/sockets/chrisbim2ree-puma.sock/contact_messages"

As far as I understand sockets are files, not directories. Here the log seems to indicate that it is a directory. The other website I mention here has similar pattern. On my system *puma.sock is not a directory. What's wrong here? Problem happens on a part of the site responsible for redirection after submitting the message.

tmp/sockets$ ls -l
total 0
srwxrwxrwx 1 chris chris 0 Jun 21 20:08 chrisbim2ree-puma.sock

my error log. $ tail -n 2 ./log/nginx.error.log

2016/06/21 20:10:30 [error] 1416#1416: *5 upstream timed out (110: Connection timed out) while reading response header from upstream,

client: 86.22.165.132, server: chrisbeard-images.com, request: "POST /contact_messages HTTP/1.1", upstream: "http://unix:///home/chris/Rails/chrisbim2ree/shared/tmp/sockets/chrisbim2ree-puma.sock/contact_messages", host: "chrisbeard-images.com", referrer: "http://chrisbeard-images.com/contact" 2016/06/21 20:13:41 [info] 1416#1416: *14 client closed connection while waiting for request, client: 86.22.165.132, server: 0.0.0.0:80

nginx config files

$ sudo cat /etc/nginx/sites-enabled/default 
[sudo] password for chris: 

upstream puma {
  server unix:///home/chris/Rails/chrisbim2ree/shared/tmp/sockets/chrisbim2ree-puma.sock;
}

server {
  listen 80 default_server deferred;
  server_name chrisbeard-images.com www.chrisbeard-images.com;

  root /home/chris/Rails/chrisbim2ree/current/public;
  access_log /home/chris/Rails/chrisbim2ree/current/log/nginx.access.log;
  error_log /home/chris/Rails/chrisbim2ree/current/log/nginx.error.log info;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  try_files $uri/index.html $uri @puma;

  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 4G;
  keepalive_timeout 70s;
}

another relevant config file

$ sudo cat /etc/nginx/nginx.conf
user www-data;
worker_processes 1;
pid /var/run/nginx.pid;

events { worker_connections 1024; }

http {
        client_max_body_size 2048M;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 70;
    types_hash_max_size 2048;
    server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

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

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

    gzip on;
    gzip_disable "msie6";
    gzip_types text/plain text/xml text/css text/comma-separated-values;
        upstream app_server { server 127.0.0.1:8080 fail_timeout=0; }

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

puma config

$ cat ./puma.rb
#!/usr/bin/env puma

directory '/home/chris/Rails/chrisbim2ree/current'
rackup "/home/chris/Rails/chrisbim2ree/current/config.ru"
environment 'production'

pidfile "/home/chris/Rails/chrisbim2ree/shared/tmp/pids/puma.pid"
state_path "/home/chris/Rails/chrisbim2ree/shared/tmp/pids/puma.state"
stdout_redirect '/home/chris/Rails/chrisbim2ree/current/log/puma.error.log', '/home/chris/Rails/chrisbim2ree/current/log/puma.access.log', true


threads 4,16

bind 'unix:///home/chris/Rails/chrisbim2ree/shared/tmp/sockets/chrisbim2ree-puma.sock'

workers 4



preload_app!


on_restart do
  puts 'Refreshing Gemfile'
  ENV["BUNDLE_GEMFILE"] = "/home/chris/Rails/chrisbim2ree/current/Gemfile"
end


on_worker_boot do
  ActiveSupport.on_load(:active_record) do
    ActiveRecord::Base.establish_connection
  end
end
  • The problem is most likely with where the upstream is configured, it looks quite wrong. I've never seen HTTP and Unix in the same URL. "upstream: http://unix:// – Tim Jun 22 '16 at 1:01
  • @Tim, I agree, but the end of the path seems to be wrong as well. What's causing it? – ruby_object Jun 22 '16 at 1:32
  • @ruby_object do you remember how you solved this? I have a similar problem and I'm baffled! – Les Nightingill Mar 3 at 23:34
1

Try this

upstream puma {
  server unix:/home/chris/Rails/chrisbim2ree/shared/tmp/sockets/chrisbim2ree-puma.sock;
}

Here's one I have defined as an example

upstream php-fpm {
  server unix:/var/run/php-fpm/php-fpm.sock;
}

I've never used @ in locations, but I had a quick read about it, nothing obvious seemed off. I'm not sure what you're trying to do with that part, can you explain further by editing your question? It looks a little suspect, but that may just be because I've never used it myself.

I'd try the upstream fix first then see what happens. If it doesn't work edit your original question to add behavior and log entries, and comment below tagging me so I get notified.

| improve this answer | |
  • the use of @ is taken from the digital ocean totorial: digitalocean.com/community/tutorials/… . It worked fine for long time problems started when I upgraded to Ubuntu 16.04. I'll try your suggestion and see what happens. – ruby_object Jun 22 '16 at 7:11
  • some progress, but everything stopped working. on every page i get this error: ---------- 2016/06/22 03:50:26 [error] 9473#9473: *1 connect() to unix:/var/run/puma/puma.sock failed (111: Connection refused) while connecting to upstream, client: 86.22.165.132, server: localhost, request: "GET / HTTP/1.1", upstream: "unix:/var/run/puma/puma.sock:", host: "chrisbeard-images.com" – ruby_object Jun 22 '16 at 8:01
  • Sorry it didn't help, that's all I've got for now. If I think of anything else I'll post. – Tim Jun 22 '16 at 9:06
  • abandon your hope trying to configure nginx. nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls perhaps it's time to look for alternatives? – ruby_object Jun 22 '16 at 9:55
  • Maybe you just need to find and pay someone appropriately skilled. Nginx is flexible, and flexibility often creates complexity. To get my own websites onto Nginx took a week or so of fairly solid work, coming from no knowledge about nginx, that was Wordpress and a custom PHP site but I had a bunch of rules to do rewrites and caching. In your place I'd remove the upstream, I'd consider proxy_pass directly rather than using redirection. I'd also try to work out why your proxy_pass has http:// in front of your upstream puma. With some thought and experimentation you'll work it out. – Tim Jun 22 '16 at 20:53
1

in your config/puma.conf there is the last block (on_worker_boot). You can remove it to have a temporary fix.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.