Amazon web services 在Elastic Beanstalk上部署Ruby Rails应用程序

Amazon web services 在Elastic Beanstalk上部署Ruby Rails应用程序,amazon-web-services,amazon-elastic-beanstalk,Amazon Web Services,Amazon Elastic Beanstalk,我一直在寻找解决这个问题的办法,但我似乎找不到确切的答案 目前,我正在遵循亚马逊提供的教程 如果我部署他们的示例应用程序并获得欢迎屏幕,一切都会正常工作 然而,当我想要部署自己的应用程序时,请遵循上面提到的教程,并使用rails生成一个scaffold项目,我得到了502 Bad Gateway 我按照教程设置了一个任意类型的“博客”,展示了数据库交互等的基础知识 我成功地: 使用rails服务器@0.0.0.0:3000/高分在本地运行服务器 rake数据库:迁移 运行包更新 运行bundle

我一直在寻找解决这个问题的办法,但我似乎找不到确切的答案

目前,我正在遵循亚马逊提供的教程

如果我部署他们的示例应用程序并获得欢迎屏幕,一切都会正常工作

然而,当我想要部署自己的应用程序时,请遵循上面提到的教程,并使用rails生成一个scaffold项目,我得到了502 Bad Gateway

我按照教程设置了一个任意类型的“博客”,展示了数据库交互等的基础知识

我成功地:

使用rails服务器@0.0.0.0:3000/高分在本地运行服务器 rake数据库:迁移 运行包更新 运行bundle安装和所有组合,以便在本地计算机上成功安装我的gems 确保git实际上通过将SSHing推送到机器EC2实例中来推送我的更新 检查我的环境:

配置: 选项26使用eb init工具:Ruby 2.0.0

用于创建RDS数据库MySql的选项是

从快照功能获取的错误/日志文件 当访问我的实例并进入/high_分数时,我会收到以下错误消息:

502坏网关

nginx/1.4.5

生产日志 一、 [2014-06-18T19:07:45.310588 4524]信息-:迁移到CreateHighScores 20140618173833 [ec2-user@ip-172-31-

-这是文件中唯一的东西

Gemfile 快照日志 请注意最后一节,它在该节中成功地迁移了项目

问题: 部署应用程序时我做错了什么? 我可以很好地访问我自己创建的index.html页面,但无法访问rails生成的“get”url端点 是否有一些配置我错过了?
在最终找到passenger.log文件后,我将secret_key添加到环境变量中以解决一个问题。这消除了我在passenger.log文件中看到的丢失secret key的错误。请查看解决方案。此外,即使您使用scaffolds构建ruby rails临时应用程序,它也无法在路由中正确放置路由s、 rb文件。我添加了get'high_scores'=>'high_scoresview',它最终加载了页面。我对ruby、rails和passenger都是新手,所以上面提到的问题可能是我对系统的知识不足。但是,如果不将此添加到运行rails服务器的本地机器上的routes文件中,它工作正常。这让我相信passenger requ请您定义这些路线以便工作。
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.1'
gem 'multi_json', '1.7.8'
gem 'json'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer',  platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring',        group: :development

# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use unicorn as the app server
# gem 'unicorn'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

# Use debugger
# gem 'debugger', group: [:development, :test]
-------------------------------------
/var/app/support/logs/passenger.log
-------------------------------------
  /usr/local/share/ruby/gems/2.0/gems/railties-4.1.1/lib/rails/initializable.rb:55:in `block in run_initializers'
  /usr/share/ruby/2.0/tsort.rb:150:in `block in tsort_each'
  /usr/share/ruby/2.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
  /usr/share/ruby/2.0/tsort.rb:219:in `each_strongly_connected_component_from'
  /usr/share/ruby/2.0/tsort.rb:182:in `block in each_strongly_connected_component'
  /usr/share/ruby/2.0/tsort.rb:180:in `each'
  /usr/share/ruby/2.0/tsort.rb:180:in `each_strongly_connected_component'
  /usr/share/ruby/2.0/tsort.rb:148:in `tsort_each'
  /usr/local/share/ruby/gems/2.0/gems/railties-4.1.1/lib/rails/initializable.rb:54:in `run_initializers'
  /usr/local/share/ruby/gems/2.0/gems/railties-4.1.1/lib/rails/application.rb:288:in `initialize!'
  /var/app/current/config/environment.rb:5:in `<top (required)>'
  config.ru:3:in `require'
  config.ru:3:in `block in <main>'
  /usr/local/share/ruby/gems/2.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
  /usr/local/share/ruby/gems/2.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
  config.ru:1:in `new'
  config.ru:1:in `<main>'
  /usr/local/share/ruby/gems/2.0/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:112:in `eval'
  /usr/local/share/ruby/gems/2.0/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:112:in `preload_app'
  /usr/local/share/ruby/gems/2.0/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:158:in `<module:App>'
  /usr/local/share/ruby/gems/2.0/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
  /usr/local/share/ruby/gems/2.0/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:28:in `<main>'

App 31927 stdout: 
App 31927 stdout: 
[ 2014-06-18 20:38:57.0761 31847/7f322494e700 Pool2/Implementation.cpp:883 ]: Could not spawn process for group /var/app/current#default: An error occured while starting up the preloader.
     in 'void Passenger::ApplicationPool2::SmartSpawner::handleErrorResponse(Passenger::ApplicationPool2::SmartSpawner::StartupDetails&)' (SmartSpawner.h:455)
     in 'std::string Passenger::ApplicationPool2::SmartSpawner::negotiatePreloaderStartup(Passenger::ApplicationPool2::SmartSpawner::StartupDetails&)' (SmartSpawner.h:566)
     in 'void Passenger::ApplicationPool2::SmartSpawner::startPreloader()' (SmartSpawner.h:206)
     in 'virtual Passenger::ApplicationPool2::ProcessPtr Passenger::ApplicationPool2::SmartSpawner::spawn(const Passenger::ApplicationPool2::Options&)' (SmartSpawner.h:752)
     in 'void Passenger::ApplicationPool2::Group::spawnThreadRealMain(const Passenger::ApplicationPool2::SpawnerPtr&, const Passenger::ApplicationPool2::Options&, unsigned int)' (Implementation.cpp:804)

[ 2014-06-18 20:38:57.0764 31847/7f3222643700 agents/HelperAgent/RequestHandler.h:2210 ]: [Client 20] Cannot checkout session.
Error page:
database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
  /usr/local/share/ruby/gems/2.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/connection_specification.rb:184:in `spec'
  /usr/local/share/ruby/gems/2.0/gems/activerecord-4.1.1/lib/active_record/connection_handling.rb:50:in `establish_connection'
  /usr/local/share/ruby/gems/2.0/gems/activerecord-4.1.1/lib/active_record/railtie.rb:129:in `block (2 levels) in <class:Railtie>'
  /usr/local/share/ruby/gems/2.0/gems/activesupport-4.1.1/lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
  /usr/local/share/ruby/gems/2.0/gems/activesupport-4.1.1/lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
  /usr/local/share/ruby/gems/2.0/gems/activesupport-4.1.1/lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
  /usr/local/share/ruby/gems/2.0/gems/activesupport-4.1.1/lib/active_support/lazy_load_hooks.rb:44:in `each'
  /usr/local/share/ruby/gems/2.0/gems/activesupport-4.1.1/lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
  /usr/local/share/ruby/gems/2.0/gems/activerecord-4.1.1/lib/active_record/base.rb:326:in `<module:ActiveRecord>'
  /usr/local/share/ruby/gems/2.0/gems/activerecord-4.1.1/lib/active_record/base.rb:23:in `<top (required)>'
  /usr/local/share/ruby/gems/2.0/gems/activerecord-4.1.1/lib/active_record/relation/predicate_builder.rb:111:in `<class:PredicateBuilder>'
  /usr/local/share/ruby/gems/2.0/gems/activerecord-4.1.1/lib/active_record/relation/predicate_builder.rb:2:in `<module:ActiveRecord>'
  /usr/local/share/ruby/gems/2.0/gems/activerecord-4.1.1/lib/active_record/relation/predicate_builder.rb:1:in `<top (required)>'
  /usr/local/share/ruby/gems/2.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
  /usr/local/share/ruby/gems/2.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `block in require'
  /usr/local/share/ruby/gems/2.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:232:in `load_dependency'
  /usr/local/share/ruby/gems/2.0/gems/activesupport-4.1.1/lib/active_support/dependencies.rb:247:in `require'
  /usr/local/share/ruby/gems/2.0/gems/activesupport-4.1.1/lib/active_support/dependencies/autoload.rb:70:in `block in eager_load!'
  /usr/local/share/ruby/gems/2.0/gems/activesupport-4.1.1/lib/active_support/dependencies/autoload.rb:70:in `each'
  /usr/local/share/ruby/gems/2.0/gems/activesupport-4.1.1/lib/active_support/dependencies/autoload.rb:70:in `eager_load!'
  /usr/local/share/ruby/gems/2.0/gems/activerecord-4.1.1/lib/active_record.rb:155:in `eager_load!'
  /usr/local/share/ruby/gems/2.0/gems/railties-4.1.1/lib/rails/application/finisher.rb:58:in `each'
  /usr/local/share/ruby/gems/2.0/gems/railties-4.1.1/lib/rails/application/finisher.rb:58:in `block in <module:Finisher>'
  /usr/local/share/ruby/gems/2.0/gems/railties-4.1.1/lib/rails/initializable.rb:30:in `instance_exec'
  /usr/local/share/ruby/gems/2.0/gems/railties-4.1.1/lib/rails/initializable.rb:30:in `run'
  /usr/local/share/ruby/gems/2.0/gems/railties-4.1.1/lib/rails/initializable.rb:55:in `block in run_initializers'
  /usr/share/ruby/2.0/tsort.rb:150:in `block in tsort_each'
  /usr/share/ruby/2.0/tsort.rb:183:in `block (2 levels) in each_strongly_connected_component'
  /usr/share/ruby/2.0/tsort.rb:219:in `each_strongly_connected_component_from'
  /usr/share/ruby/2.0/tsort.rb:182:in `block in each_strongly_connected_component'
  /usr/share/ruby/2.0/tsort.rb:180:in `each'
  /usr/share/ruby/2.0/tsort.rb:180:in `each_strongly_connected_component'
  /usr/share/ruby/2.0/tsort.rb:148:in `tsort_each'
  /usr/local/share/ruby/gems/2.0/gems/railties-4.1.1/lib/rails/initializable.rb:54:in `run_initializers'
  /usr/local/share/ruby/gems/2.0/gems/railties-4.1.1/lib/rails/application.rb:288:in `initialize!'
  /var/app/current/config/environment.rb:5:in `<top (required)>'
  config.ru:3:in `require'
  config.ru:3:in `block in <main>'
  /usr/local/share/ruby/gems/2.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
  /usr/local/share/ruby/gems/2.0/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
  config.ru:1:in `new'
  config.ru:1:in `<main>'
  /usr/local/share/ruby/gems/2.0/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:112:in `eval'
  /usr/local/share/ruby/gems/2.0/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:112:in `preload_app'
  /usr/local/share/ruby/gems/2.0/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:158:in `<module:App>'
  /usr/local/share/ruby/gems/2.0/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
  /usr/local/share/ruby/gems/2.0/gems/passenger-4.0.41/helper-scripts/rack-preloader.rb:28:in `<main>'


/var/log/directory-hooks-executor.log
-------------------------------------
Resolving dependencies...
Using rake 10.3.2
Using i18n 0.6.9
Using json 1.8.1
Using minitest 5.3.5
Using thread_safe 0.3.4
Using tzinfo 1.2.1
Using activesupport 4.1.1
Using builder 3.2.2
Using erubis 2.7.0
Using actionview 4.1.1
Using rack 1.5.2
Using rack-test 0.6.2
Using actionpack 4.1.1
Using mime-types 1.25.1
Using polyglot 0.3.5
Using treetop 1.4.15
Using mail 2.5.4
Using actionmailer 4.1.1
Using activemodel 4.1.1
Using arel 5.0.1.20140414130214
Using activerecord 4.1.1
Using bundler 1.6.2
Using coffee-script-source 1.7.0
Using execjs 2.2.0
Using coffee-script 2.2.0
Using thor 0.19.1
Using railties 4.1.1
Using coffee-rails 4.0.1
Using hike 1.2.3
Using multi_json 1.7.8
Using jbuilder 2.1.1
Using jquery-rails 3.1.0
Using mysql2 0.3.16
Using tilt 1.4.1
Using sprockets 2.11.0
Using sprockets-rails 2.1.3
Using rails 4.1.1
Using rdoc 4.1.1
Using sass 3.2.19
Using sass-rails 4.0.3
Using sdoc 0.4.0
Using turbolinks 2.2.2
Using uglifier 2.5.1
Your bundle is complete!
Gems in the groups test and development were not installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
+ '[' 0 '!=' 0 ']'
+ echo 'bundle install succeeded'
bundle install succeeded
+ '[' -f Gemfile.lock ']'
+ echo 'encountered a Gemfile.lock, setting proper permissions'
encountered a Gemfile.lock, setting proper permissions
+ chown webapp:webapp Gemfile.lock
+ '[' '' = 1 ']'
+ true

2014-06-18 20:41:08,496 [INFO] (32051 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Script succeeded.
2014-06-18 20:41:08,496 [INFO] (32051 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Executing script: /opt/elasticbeanstalk/hooks/appdeploy/pre/11_asset_compilation.sh
2014-06-18 20:41:15,728 [INFO] (32051 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Output from script: running 'rake assets:precompile'...
I, [2014-06-18T20:41:15.568942 #32080]  INFO -- : Writing /var/app/ondeck/public/assets/application-10faafa06109fa14582542ac1852f5c5.js
I, [2014-06-18T20:41:15.633955 #32080]  INFO -- : Writing /var/app/ondeck/public/assets/application-cf0b4d12cded06d61176668723302161.css
Asset compilation succesful

2014-06-18 20:41:15,729 [INFO] (32051 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Script succeeded.
2014-06-18 20:41:15,729 [INFO] (32051 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Executing script: /opt/elasticbeanstalk/hooks/appdeploy/pre/12_db_migration.sh
2014-06-18 20:41:18,817 [INFO] (32051 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Output from script: == 20140618173833 CreateHighScores: migrating =================================
-- create_table(:high_scores)
   -> 0.1183s
== 20140618173833 CreateHighScores: migrated (0.1184s) ========================


2014-06-18 20:41:18,817 [INFO] (32051 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Script succeeded.
2014-06-18 20:41:18,954 [INFO] (32096 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Executing directory: /opt/elasticbeanstalk/hooks/appdeploy/enact/
2014-06-18 20:41:18,955 [INFO] (32096 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Executing script: /opt/elasticbeanstalk/hooks/appdeploy/enact/01_flip.sh
2014-06-18 20:41:19,006 [INFO] (32096 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Output from script: + '[' -d /var/app/current ']'
+ rm -rf /var/app/current.old
+ mv /var/app/current /var/app/current.old
+ mv /var/app/ondeck /var/app/current
+ su -c 'mkdir -p /var/app/current/{tmp,public}' webapp
+ rm -rf /var/app/current.old

2014-06-18 20:41:19,006 [INFO] (32096 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Script succeeded.
2014-06-18 20:41:19,007 [INFO] (32096 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Executing script: /opt/elasticbeanstalk/hooks/appdeploy/enact/09clean.sh
2014-06-18 20:41:19,021 [INFO] (32096 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Output from script: 
2014-06-18 20:41:19,021 [INFO] (32096 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Script succeeded.
2014-06-18 20:41:19,021 [INFO] (32096 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Executing script: /opt/elasticbeanstalk/hooks/appdeploy/enact/99_reload_app_server.sh
2014-06-18 20:41:19,532 [INFO] (32096 MainThread) [directoryHooksExecutor.py-29] [root directoryHooksExecutor info] Output from script: =============== Phusion Passenger Standalone web server started ===============
PID file: /var/app/support/pids/passenger.pid
Log file: /var/app/support/logs/passenger.log
Environment: production
Accessible via: http://0.0.0.0/

Serving in the background as a daemon.
Problems? Check http://www.modrails.com/documentation/Users%20guide%20Standalone.html#troubleshooting
===============================================================================