【问题标题】:Puma not running in production ec2Puma 没有在生产 ec2 中运行
【发布时间】:2018-01-01 12:20:29
【问题描述】:

我正在尝试使用 nginx、puma 和 capistrano 将我的网站部署到 amazon ec2 我按照本教程 https://medium.com/@henslejoseph/deployment-a-rails-app-to-ec2-using-bitbucket-and-semaphoreci-d539bea90db3 将应用程序部署到服务器但是当我尝试通过浏览器通过浏览器访问它时转到网站 url 它说这个网站无法访问。我尝试的下一件事是检查 nginx 和 puma 日志,我在 nginx 日志中找不到任何东西,但在 puma_access.log 中有错误 Errno::EADDRINUSE: Address already in use - bind(2) for " 0.0.0.0" 端口 3000。在此之后,我尝试使用 lsof -wni tcp:3000 和 netstat -an | 检查是否有任何进程正在使用端口 3000 grep 3000 但输出为空似乎没有进程附加到端口。 我正在尝试从 3 天开始调试它,但仍然不知道发生了什么。非常感谢任何帮助我只是附上我所有的配置文件以供参考。

capfile # 加载 DSL 并设置阶段 需要“capistrano/设置”

# Include default deployment tasks
require "capistrano/deploy"

    require "capistrano/scm/git"
    install_plugin Capistrano::SCM::Git


# Load the SCM plugin appropriate to your project:
#
# require "capistrano/scm/hg"
# install_plugin Capistrano::SCM::Hg
# or
# require "capistrano/scm/svn"
# install_plugin Capistrano::SCM::Svn
# or
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git

# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
#   https://github.com/capistrano/rvm
#   https://github.com/capistrano/rbenv
#   https://github.com/capistrano/chruby
#   https://github.com/capistrano/bundler
#   https://github.com/capistrano/rails
#   https://github.com/capistrano/passenger
#
require "capistrano/rvm"
# require "capistrano/rbenv"
# require "capistrano/chruby"
require "capistrano/bundler"
require "capistrano/rails/assets"
require "capistrano/rails/migrations"
require "capistrano/puma"
# require "capistrano/passenger"

# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }

deploy.rb

# config valid for current version and patch releases of Capistrano
lock "~> 3.10.1"

set :application, "myappname"
set :repo_url, "myapp_url"

# Default branch is :master
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp

set :branch, :deployment_work

# Default deploy_to directory is /var/www/my_app_name
# set :deploy_to, "/var/www/my_app_name"
 set :deploy_to, '/home/yogesh/myapp_name'
 # set :scm, :git

# Default value for :format is :airbrussh.
# set :format, :airbrussh

# You can configure the Airbrussh format using :format_options.
# These are the defaults.
# set :format_options, command_output: true, log_file: "log/capistrano.log", color: :auto, truncate: :auto

# Default value for :pty is false
set :pty, true

# Default value for :linked_files is []
# append :linked_files, "config/database.yml", "config/secrets.yml"

set :linked_files, fetch(:linked_files, []).push('config/database.yml', 'config/secrets.yml', 'config/application.yml')

set :rvm_type, :user

set :rvm_ruby_version, 'ruby-2.3.3'

set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp/pids', 'tmp/cache', 'tmp/sockets', 'vendor/bundle', 'public/system')
set :keep_releases, 3
# Default value for linked_dirs is []
# append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/system"

# Default value for default_env is {}
# set :default_env, { path: "/opt/ruby/bin:$PATH" }

# Default value for local_user is ENV['USER']
# set :local_user, -> { `git config user.name`.chomp }

# Default value for keep_releases is 5
# set :keep_releases, 5

# Uncomment the following to require manually verifying the host key before first deploy.
# set :ssh_options, verify_host_key: :secure

    # Pume config
    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"    #accept array for multi-bind
    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

production.rb

set :stage, :production
    # Replace this EC2 server's public IP with your EC2 server's public IP
    # Replace this user ('sarmad') with the one you created on your EC2 instance
    server 'xx.xxx.xxx.xx', user: 'yogesh', roles: %w{web app db}

    set :ssh_options,{ forward_agent: true, user: 'yogesh', keys: %w(~/.ssh/id_rsa) }

puma.rb

#!/usr/bin/env puma

directory '/home/yogesh/myapp_name/current'
rackup "/home/yogesh/myapp_name/current/config.ru"
environment 'production'

pidfile "/home/yogesh/myapp_name/shared/tmp/pids/puma.pid"
state_path "/home/yogesh/myapp_name/shared/tmp/pids/puma.state"
stdout_redirect '/home/yogesh/myapp_name/shared/log/puma_error.log', '/home/yogesh/myapp_name/shared/log/puma_access.log', true


threads 0,8

bind 'unix:///home/yogesh/myapp_name/shared/tmp/sockets/puma.sock'

workers 0



prune_bundler


on_restart do
  puts 'Refreshing Gemfile'
  ENV["BUNDLE_GEMFILE"] = ""
end

nginxconfig

upstream app {
      # Path to Puma SOCK file, as defined previously
      server unix:///home/yogesh/myapp_name/shared/tmp/sockets/puma.sock fail_timeout=0;
    }
    server {
      listen 80;
      server_name localhost;
      root /home/yogesh/myapp_name/current/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;
    }

有人可以帮我解决问题的地方吗?我已经尝试了所有 stackoverflow 问题,并且从 3 天开始在 Google 上搜索了很多,但仍然不知道我的配置有什么问题。

【问题讨论】:

    标签: ruby-on-rails nginx amazon-ec2 puma capistrano3


    【解决方案1】:

    更新:经过大量研究,我得到了解决方案 您所要做的就是确保sites_available 文件夹中的默认文件也应该在sites_enabled 文件夹中可用。此默认文件确保网站已启用。如果默认文件不可用,则似乎nginx 没有在端口80 上侦听。

    【讨论】:

      猜你喜欢
      • 2016-10-19
      • 2021-07-01
      • 1970-01-01
      • 2015-07-05
      • 1970-01-01
      • 1970-01-01
      • 2019-07-09
      • 2017-11-08
      • 2015-12-16
      相关资源
      最近更新 更多