使用 Capistrano 和 Puma部署 Rails 5 API



我正在尝试将带有Capistrano的Rails 5 API部署到AWS服务器,但我遇到了一些问题...

我已经遵循了本教程,因此我尝试使用以下命令进行部署:

$ cap production deploy

这将生成一个以以下内容结尾的日志:

00:20 deploy:log_revision
01 echo "Branch master (at <uuid>) deployed as release 20180315215050 by <user>" >> /<path_to_app>/revisions.log
✔ 01 <user>@<Public DNS (IPv4)> 0.206s

一切似乎都还好,我猜。但是当我查询服务器时,我收到了来自nginx的502错误网关。 当我$ ps aux | grep puma$ ps aux | grep rails时,我没有发现任何进程正在运行......

我的配置文件如下:

盖文件

# Load DSL and set up stages
require 'capistrano/setup'
# Include default deployment tasks
require 'capistrano/deploy'
# Load the SCM plugin appropriate to your project:
require 'capistrano/scm/git'
install_plugin Capistrano::SCM::Git
require 'capistrano/rvm'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
require 'capistrano/puma'
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

config/deploy.rb

# config valid for current version and patch releases of Capistrano
lock '~> 3.10.1'
set :application, '<app_name>'
set :repo_url, '<git_repo>'
set :branch, 'master'
set :deploy_to, '/<path_to_app>'
set :pty, true
set :ssh_options, {
forward_agent: true,
auth_methods: ['publickey'],
keys: ['/<path_to_key>.pem']
}
set :linked_files, %w{config/database.yml config/application.yml}
set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system public/uploads}
set :keep_releases, 5
set :rvm_type, :user
set :rvm_ruby_version, '2.5.0'
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, [1, 8]
set :puma_workers, 0
set :puma_worker_timeout, nil
set :puma_init_active_record, true
set :puma_preload_app, false

@server:/etc/nginx/sites-available/default

upstream app {
# Path to Puma SOCK file, as defined previously
server unix:/<path_to_app>/shared/tmp/sockets/puma.sock fail_timeout=0;
}
server {
listen 80;
server_name localhost;
root /<path_to_app>/public;
try_files $uri/index.html $uri @app;
location / {
proxy_set_header X-Forwared-Proto $scheme;
proxy_set_header X-Forwared-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Connection '';
proxy_pass http://app;
}
location ~ ^/(assets|fonts|system)/|favicon.ico|robots.txt {
gzip_static on;
expires max;
add_header Cache-control public;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}

谁能弄清楚我做错了什么?

非常感谢!

您应该手动设置参数<...>

对于配置/部署.rb

set :application, '<app_name>'
set :repo_url, '<git_repo>'
set :deploy_to, '/<path_to_app>'

set :ssh_options, {
forward_agent: true,
auth_methods: ['publickey'],
keys: ['/<path_to_key>.pem']
}

对于@server:/etc/nginx/sites-available/default

server unix:/<path_to_app>/shared/tmp/sockets/puma.sock fail_timeout=0;

root /<path_to_app>/public;

最新更新