部署Rails应用程序时遇到Puma问题(在EC2上使用Capistrano)

时间:2018-04-11 04:17:26

标签: ruby-on-rails amazon-web-services

我第一次尝试在EC2上部署Rails应用程序,但这样做并不成功。我的应用在本地工作。当我执行cap production deploy时,它部署时没有任何错误,似乎数据库已迁移并显示在我的EC2服务器上,但是我无法访问该页面并收到超时错误。此外,当我尝试重新启动Nginx时,没有任何反应。我认为问题在于Puma。

当我检查puma.sock文件所在的路径时,该目录为空。我试图手动启动Puma,用

创建一个文件
bundle exec puma -e production -b unix:///home/deploy/byc/shared/tmp/sockets/puma.sock

并没有开始。我收到错误:

[28924] Puma starting in cluster mode...
[28924] * Version 3.11.3 (ruby 2.5.0-p0), codename: Love Song
[28924] * Min threads: 5, max threads: 5
[28924] * Environment: production
[28924] * Process workers: 2
[28924] * Preloading application
[28924] * Listening on unix:///home/deploy/byc/shared/tmp/sockets/puma.sock
bundler: failed to load command: puma (/Users/matt/.rbenv/versions/2.5.0/bin/puma)

毋庸置疑,当Capistrano打开并且我无法部署应用程序时,它也无效。

这是我第一次部署任何内容,过去两天我已经完成了几十个问题而且不知道该怎么做。如果有人能指出我正确的方向,我将永远感激。

的/ etc / nginx的/位点可用/默认

upstream app {
  # Path to Puma SOCK file, as defined previously
  server unix:/home/deploy/byc/shared/tmp/sockets/puma.sock         fail_timeout=0;
}

server {
  listen 80;
  server_name localhost;
  root /home/deploy/byc/public;
  try_files $uri/index.html $uri @app;

  location / {
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-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;
}

/etc/nginx/nginx./conf

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";


        ##
        # Virtual Host Configs
        ##

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

http {
    disable_symlinks off;
}

production.rb

server 'xx.xxx.xx.xx', user: 'deploy', roles: %w{web app db}

Capfile

require "capistrano/setup"
require "capistrano/deploy"
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'
install_plugin Capistrano::Puma

Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }

deploy.rb

lock "~> 3.10.1"

set :application, 'byc'
set :repo_url, 'git@github.com:githubusername/byc2.git'
set :branch, :master
set :deploy_to, '/home/deploy/byc'
set :user, 'deploy'
set :pty, true
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, 'ruby-2.5.0' # Edit this if you are using MRI Ruby

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/#{fetch(:application)}-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

namespace :deploy do
  after :restart, :clear_cache do
    on roles(:web), in: :groups, limit: 3, wait: 10 do
    end
  end
end

的database.yml

development: 
  adapter: postgresql
  encoding: unicode
  database: byc-master_db
  pool: 5
  username: matt
  password:
  host: localhost
  timeout: 5432

production:
  adapter: postgresql
  encoding: unicode
  database: byc_production
  username: byc
  password: *****
  host: localhost
  port: 5432

0 个答案:

没有答案