如何调试Puma sock连接

时间:2016-04-15 16:54:41

标签: ruby-on-rails nginx capistrano puma

更新

来自@ BoraMa的评论 - 我意识到我的puma.rb(这都是样板)并没有正确设置套接字位置。但是,我不确定如何进行这些匹配...我的袜子位置在哪里都很重要?我可以把它放在任何地方吗?

我的网站可用文件的路径是 -

"unix:///home/deploy/apps/mll/shared/tmp/sockets/mll-puma.sock:/"

然而,我退出了下面看到的app_dir,我得到了:

/home/deploy/apps/mll/releases/20160415184544

所以我不确定如何让这些匹配/我应该使用它,因为它看起来像是在puma.rb中使用我的capistrano版本

我更新的puma.rb

# Change to match your CPU core count
workers 1

# Min and Max threads per worker
threads 1, 6

app_dir = File.expand_path("../..", __FILE__)
puts "App dir: #{app_dir}"
# App dir: /home/deploy/apps/mll/releases/20160415184544
shared_dir = "#{app_dir}"

# Default to production
rails_env = ENV['RAILS_ENV'] || "production"
environment rails_env

# Set up socket location
# bind "unix://#{shared_dir}/sockets/puma.sock"
bind "unix://#{shared_dir}/tmp/sockets/mll-puma.sock"

# Logging
stdout_redirect "#{shared_dir}/log/puma.stdout.log", "#{shared_dir}/log/puma.stderr.log", true

# Set master PID and state locations
pidfile "#{shared_dir}/pids/puma.pid"
state_path "#{shared_dir}/pids/puma.state"
activate_control_app

on_worker_boot do
  require "active_record"
  ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
  ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env])
end

注意 - 我最初关注的是:https://www.digitalocean.com/community/tutorials/deploying-a-rails-app-on-ubuntu-14-04-with-capistrano-nginx-and-puma

原帖

我试图在Nginx上通过Capistrano / Capistrano宝石运行Puma for rails app。

运行cap production deploy:initial并加载浏览器后,我得到An unhandled lowlevel error occurred. The application logs may have details.

我对Puma / Sockets / Permissions不是很熟悉。

我的日志显示:

[crit] 27411#0: *2 connect() to unix:///home/deploy/apps/mll/shared/tmp/sockets/mll-puma.sock failed (13: Permission denied) while connecting to upstream, 

client: my_ip_address, 
server: mysite.com, 
request: "GET / HTTP/1.1", 
upstream: "http://unix:///home/deploy/apps/mll/shared/tmp/sockets/mll-puma.sock:/", 
host: "centers.m$

/ etc / nginx / sites-available / centers -

upstream mll-puma {
  server unix:///home/deploy/apps/mll/shared/tmp/sockets/mll-puma.sock;
}

server {
  listen 80 default_server;
  listen [::]:80 default_server ipv6only=on;

  root /home/deploy/apps/mll/current/public;
  access_log /home/deploy/apps/mll/current/log/nginx.access.log;
  error_log /home/deploy/apps/mll/current/log/nginx.error.log info;

  server_name centers.mrs-lodges-library.com;

  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://mll-puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 10M;
  keepalive_timeout 10;
}
puma.rb,几乎是样板,没有改变任何设置

# Change to match your CPU core count
workers 1

# Min and Max threads per worker
threads 1, 6

app_dir = File.expand_path("../..", __FILE__)
shared_dir = "#{app_dir}/shared"

# Default to production
rails_env = ENV['RAILS_ENV'] || "production"
environment rails_env

# Set up socket location
bind "unix://#{shared_dir}/sockets/puma.sock"

# Logging
stdout_redirect "#{shared_dir}/log/puma.stdout.log", "#{shared_dir}/log/puma.stderr.log", true

# Set master PID and state locations
pidfile "#{shared_dir}/pids/puma.pid"
state_path "#{shared_dir}/pids/puma.state"
activate_control_app

on_worker_boot do
  require "active_record"
  ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
  ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env])
end

/etc/nginx/nginx.conf

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
  worker_connections 768;
  # multi_accept on;
}

http {
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;

  server_names_hash_bucket_size 64;


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

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

权限:

namei -l / var / www / centers /

drwxr-xr-x root root /
drwxr-xr-x root root var
drwxr-xr-x root root www
drwxrwxr-x root root centers

namei -l / home / deploy / apps / mll / current / public /

drwxr-xr-x root   root   /
drwxr-xr-x root   root   home
drwxr-xr-x deploy deploy deploy
drwxr-xr-x deploy deploy apps
drwxr-xr-x deploy deploy mll
lrwxrwxrwx deploy deploy current -> /home/deploy/apps/mll/releases/20160415164906
drwxr-xr-x root   root     /
drwxr-xr-x root   root     home
drwxr-xr-x deploy deploy   deploy
drwxr-xr-x deploy deploy   apps
drwxr-xr-x deploy deploy   mll
drwxr-xr-x deploy deploy   releases
drwxrwxr-x deploy deploy   20160415164906
drwxrwxr-x deploy deploy public
deploy@banana:/etc/nginx$

套接字 -

$ ls -l <​​/ p>

drwxr-xr-x 2 deploy deploy 4096 Apr 14 18:22 pids
drwxr-xr-x 2 deploy deploy 4096 Apr 14 18:22 sockets

$ ls -l <​​/ p>

srwxrwxrwx 1 deploy deploy 0 Apr 14 18:22 mll-puma.sock

1 个答案:

答案 0 :(得分:0)

我认为在您的puma.rbnginx站点配置文件中,您应该将puma / nginx指向同一个套接字。现在有不同的路径。