尝试诊断与重定向有关的奇怪的 nginx 110 连接超时错误

尝试诊断与重定向有关的奇怪的 nginx 110 连接超时错误

我正在尝试诊断 ubuntu 16.04 上的服务器超时问题。我看过这个网站http://blogs.candoerz.com/question/161218/cannot-figure-out-nginx--puma-timeout-110-connection-timed-out.aspx 那里给出的建议没有起作用。然而该网站并没有解决我所关心的问题:

错误日志的一部分看起来特别奇怪

上游的: ”http://unix:///home/chris/Rails/chrisbim2ree/shared/tmp/sockets/chrisbim2ree-puma.sock/contact_messages

据我所知,套接字是文件,而不是目录。这里的日志似乎表明它是一个目录。我在这里提到的另一个网站也有类似的模式。在我的系统上,*puma.sock 不是目录。这里出了什么问题?问题发生在网站负责提交消息后重定向的部分。

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

我的错误日志。$ 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,

客户端:86.22.165.132,服务器:chrisbeard-images.com,请求:“POST /contact_messages HTTP/1.1”,上游:“http://unix:///home/chris/Rails/chrisbim2ree/shared/tmp/sockets/chrisbim2ree-puma.sock/contact_messages", 主机:“chrisbeard-images.com”, 引用者:“http://chrisbeard-images.com/contact“2016/06/21 20:13:41 [信息] 1416#1416:*14 客户端在等待请求时关闭连接,客户端:86.22.165.132,服务器:0.0.0.0:80

nginx 配置文件

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

另一个相关的配置文件

$ 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/*;
}

美洲豹配置

$ 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

答案1

尝试这个

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

下面是我定义的一个例子

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

我从未在位置中使用过 @,但我快速阅读了一下,似乎没有什么明显的问题。我不确定你想用那部分做什么,你能通过编辑你的问题进一步解释一下吗?这看起来有点可疑,但这可能只是因为我自己从未使用过它。

我会先尝试上游修复,然后看看会发生什么。如果它不起作用,请编辑您的原始问题以添加行为和日志条目,并在下面评论并标记我,以便我收到通知。

答案2

在您的 config/puma.conf 中有最后一个块 (on_worker_boot)。您可以将其删除以进行临时修复。

相关内容