使用 nginx 反向代理的 Puma 静默崩溃
Puma silent crash with nginx reverse proxy
我在 AWS EC2 实例上的 rails 应用程序上有一个美洲狮服务器 运行 ruby。有一段时间它工作正常,但我发现它在几个小时后响应 502 错误。该应用程序是使用 capistrano 部署的。
简单重启 puma 暂时解决了这个问题,但我想防止它再次发生。不太确定先尝试什么。
这是我的 capistrano puma 配置:
set :puma_rackup, -> { File.join(current_path, 'config.ru') }
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock"
set :puma_conf, "#{shared_path}/puma.rb"
set :puma_access_log, "#{shared_path}/log/puma.error.log"
set :puma_error_log, "#{shared_path}/log/puma.access.log"
set :puma_role, :app
set :puma_env, fetch(:rack_env, fetch(:rails_env, 'production'))
set :puma_threads, [0, 8]
set :puma_workers, 0
set :puma_worker_timeout, nil
set :puma_init_active_record, true
set :puma_preload_app, false
set :bundle_gemfile, -> { release_path.join('Gemfile') }
Puma 错误日志未显示任何崩溃。
Nginx 错误日志显示(xx'd out client ip):
2016/08/09 06:25:52 [error] 1081#0: *348 connect() to unix:///home/deploy/myapp/shared/tmp/sockets/puma.sock 在连接到上游时失败(111:连接被拒绝),客户端:xx.xx.xx.xx,服务器:example.com,请求:"POST /mypath HTTP/1.1",上游:“http://unix:///home/deploy/myapp/shared/tmp/sockets/puma.sock:/mypath”,主机:"example.com"
Ok, thanks for the config. That all looks fine so my guess is you're getting a process crash due to a bad extension. Since you're in production, I'd suggest uncommenting the workers line and using at least 2 workers. That will at least shield you from the crashes a little because the other worker will be able to handle traffic while the crashed one is automatically restarted.
我在 AWS EC2 实例上的 rails 应用程序上有一个美洲狮服务器 运行 ruby。有一段时间它工作正常,但我发现它在几个小时后响应 502 错误。该应用程序是使用 capistrano 部署的。
简单重启 puma 暂时解决了这个问题,但我想防止它再次发生。不太确定先尝试什么。
这是我的 capistrano puma 配置:
set :puma_rackup, -> { File.join(current_path, 'config.ru') }
set :puma_state, "#{shared_path}/tmp/pids/puma.state"
set :puma_pid, "#{shared_path}/tmp/pids/puma.pid"
set :puma_bind, "unix://#{shared_path}/tmp/sockets/puma.sock"
set :puma_conf, "#{shared_path}/puma.rb"
set :puma_access_log, "#{shared_path}/log/puma.error.log"
set :puma_error_log, "#{shared_path}/log/puma.access.log"
set :puma_role, :app
set :puma_env, fetch(:rack_env, fetch(:rails_env, 'production'))
set :puma_threads, [0, 8]
set :puma_workers, 0
set :puma_worker_timeout, nil
set :puma_init_active_record, true
set :puma_preload_app, false
set :bundle_gemfile, -> { release_path.join('Gemfile') }
Puma 错误日志未显示任何崩溃。
Nginx 错误日志显示(xx'd out client ip): 2016/08/09 06:25:52 [error] 1081#0: *348 connect() to unix:///home/deploy/myapp/shared/tmp/sockets/puma.sock 在连接到上游时失败(111:连接被拒绝),客户端:xx.xx.xx.xx,服务器:example.com,请求:"POST /mypath HTTP/1.1",上游:“http://unix:///home/deploy/myapp/shared/tmp/sockets/puma.sock:/mypath”,主机:"example.com"
Ok, thanks for the config. That all looks fine so my guess is you're getting a process crash due to a bad extension. Since you're in production, I'd suggest uncommenting the workers line and using at least 2 workers. That will at least shield you from the crashes a little because the other worker will be able to handle traffic while the crashed one is automatically restarted.