【发布时间】:2016-08-07 18:15:49
【问题描述】:
更新
来自@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 gem 为 Rails 应用程序运行 Puma。
运行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
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
srwxrwxrwx 1 deploy deploy 0 Apr 14 18:22 mll-puma.sock
【问题讨论】:
标签: ruby-on-rails nginx capistrano puma