【问题标题】:Deploy Rails 5 API with Capistrano and Puma使用 Capistrano 和 Puma 部署 Rails 5 API
【发布时间】:2018-08-24 21:25:13
【问题描述】:

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

我已按照this 教程进行操作,因此我尝试使用以下命令进行部署:

$ 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 Bad Gateway。 当我$ ps aux | grep puma$ ps aux | grep rails 时,我没有发现任何进程正在运行...

我的配置文件如下:

Capfile

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

谁能找出我做错了什么?

非常感谢!

【问题讨论】:

    标签: ruby-on-rails nginx deployment capistrano puma


    【解决方案1】:

    你应该手动设置参数&lt;...&gt;

    对于 config/deploy.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;
    

    【讨论】:

    • 我是写那些&lt;...&gt; 来匿名我的代码的人。我的代码中实际上并没有它们。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-16
    • 1970-01-01
    • 2018-01-30
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    相关资源
    最近更新 更多