Puma 未 运行 生产 ec2
Puma not running in production ec2
我正在尝试使用 nginx、puma 和 capistrano 将我的网站部署到 amazon ec2 我遵循了本教程 https://medium.com/@henslejoseph/deployment-a-rails-app-to-ec2-using-bitbucket-and-semaphoreci-d539bea90db3 应用程序已部署到服务器但是当我尝试通过浏览器访问它时访问网站 url 它说这个网站不能 reached.The 接下来我尝试检查 nginx 和 puma 日志 我在 nginx 日志中没有找到任何东西但是在 puma_access.log 中有错误 Errno::EADDRINUSE:地址已在使用 - bind(2) for "0.0.0.0" port 3000.After 我尝试使用 lsof -wni tcp:3000 和 netstat -an 检查是否有任何进程正在使用端口 3000 | grep 3000 但输出为空似乎没有进程附加到端口。
我尝试从 3 天开始对其进行调试,但仍然不知道什么是 going.Any 非常感谢帮助我只是附上我所有的配置文件以供参考。
capfile
# 加载 DSL 并设置阶段
需要 "capistrano/setup"
# 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;
}
谁能帮我解决我哪里出错的问题已经尝试了所有 Whosebug 问题并在 3 天内用谷歌搜索了很多仍然不知道我的配置有什么问题。
更新:经过大量研究,我得到了解决方案
您所要做的就是确保 sites_available 文件夹中的默认文件也应该在 sites_enabled 中可用 folder.This 默认文件确保该网站是 enabled.If 默认文件不是似乎 nginx 没有在端口 80 上监听。
我正在尝试使用 nginx、puma 和 capistrano 将我的网站部署到 amazon ec2 我遵循了本教程 https://medium.com/@henslejoseph/deployment-a-rails-app-to-ec2-using-bitbucket-and-semaphoreci-d539bea90db3 应用程序已部署到服务器但是当我尝试通过浏览器访问它时访问网站 url 它说这个网站不能 reached.The 接下来我尝试检查 nginx 和 puma 日志 我在 nginx 日志中没有找到任何东西但是在 puma_access.log 中有错误 Errno::EADDRINUSE:地址已在使用 - bind(2) for "0.0.0.0" port 3000.After 我尝试使用 lsof -wni tcp:3000 和 netstat -an 检查是否有任何进程正在使用端口 3000 | grep 3000 但输出为空似乎没有进程附加到端口。 我尝试从 3 天开始对其进行调试,但仍然不知道什么是 going.Any 非常感谢帮助我只是附上我所有的配置文件以供参考。
capfile # 加载 DSL 并设置阶段 需要 "capistrano/setup"
# 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;
}
谁能帮我解决我哪里出错的问题已经尝试了所有 Whosebug 问题并在 3 天内用谷歌搜索了很多仍然不知道我的配置有什么问题。
更新:经过大量研究,我得到了解决方案 您所要做的就是确保 sites_available 文件夹中的默认文件也应该在 sites_enabled 中可用 folder.This 默认文件确保该网站是 enabled.If 默认文件不是似乎 nginx 没有在端口 80 上监听。