gpt4 book ai didi

ruby-on-rails-4 - Rails 4 : How to add ENVIRONMENT VARIABLES on Ubuntu 14. 04 使用 RVM?

转载 作者:行者123 更新时间:2023-12-04 07:08:29 24 4
gpt4 key购买 nike

现在我正在尝试将我的 Ruby on Rails 应用程序部署到运行 Ubuntu 的 Windows Azure 上的虚拟机,但我可以修复 de set environment variables 错误,如下所述。

我已将变量添加到我的 .bashrc 中,现在在 /etc/environment 中,但错误是相同的:

App 1227 stderr: [ 2015-10-06 04:10:57.3814 1352/0x9020d38(Worker 1) utils.rb:86 ]: *** Exception RuntimeError in Rack application object (Missing `secret_to$
App 1227 stderr: from /home/deploy/apps/matching_people/shared/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/application.rb:534:in `validate_secret_$
App 1227 stderr: from /home/deploy/apps/matching_people/shared/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/application.rb:246:in `env_config'
App 1227 stderr: from /home/deploy/apps/matching_people/shared/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/engine.rb:514:in `call'
App 1227 stderr: from /home/deploy/apps/matching_people/shared/bundle/ruby/2.2.0/gems/railties-4.2.4/lib/rails/application.rb:165:in `call'
App 1227 stderr: from /usr/lib/ruby/vendor_ruby/phusion_passenger/rack/thread_handler_extension.rb:94:in `process_request'
App 1227 stderr: from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:151:in `accept_and_process_next_request'
App 1227 stderr: from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler/thread_handler.rb:112:in `main_loop'
App 1227 stderr: from /usr/lib/ruby/vendor_ruby/phusion_passenger/request_handler.rb:415:in `block (3 levels) in start_threads'
App 1227 stderr: from /usr/lib/ruby/vendor_ruby/phusion_passenger/utils.rb:112:in `block in create_thread_and_abort_on_exception'
[ 2015-10-06 04:10:57.3819 988/b5efeb40 age/Cor/Req/Utils.cpp:95 ]: [Client 1-1] Sending 502 response: application did not send a complete response

这是我的 sudo nano/etc/environment 文件:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

export SECRET_KEY_BASE=2da0d3f0bfd7b9b05110bfad512f42df2d2bb2ef715c4e831caba96a9c0b2141fbfa718dff2f5daf916cd70a70afd1f24df49884c561fbbaf364b36652b2c7d1
ruby -e 'p ENV["SECRET_KEY_BASE"]'

export MATCH_PEOPLE_DATABASE_PASSWORD=2015deployer
ruby -e 'p ENV["MATCH_PEOPLE_DATABASE_PASSWORD"]'

当我运行 echo $SECRET_KEY_BASEecho $MATCH_PEOPLE_DATABASE_PASSWORD 时,我得到了准确的数据。

deploy@vmw-ubuserver:~$ echo $SECRET_KEY_BASE
2da0d3f0bfd7b9b05110bfad512f42df2d2bb2ef715c4e831caba96a9c0b2141fbfa718dff2f5daf916cd70a70afd1f24df49884c561fbbaf364b36652b2c7d1

deploy@vmw-ubuserver:~$ echo $MATCH_PEOPLE_DATABASE_PASSWORD
2015deployer

但我在生产环境中仍然遇到同样的错误,我在 Ubuntu 14.04 上使用 RVM、Capistrano、Passenger 和 NGINX。

我的数据库.yml:

production:
adapter: mysql2
encoding: utf8
pool: 5
host: localhost
database: matchpeople_production
username: deployer
password: <%= ENV['MATCH_PEOPLE_DATABASE_PASSWORD'] %>

我的 secret .yml:

# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
secret_token: <%= ENV["SECRET_KEY_BASE"] %>

有什么帮助吗?

最佳答案

寻找并寻找正确的答案我已经尝试了太多的选择,但我没有让它正常工作。

所以,当我测试在谷歌上找到的一些配置时,突然我找到了解决方案。

很简单,就是:

  • 添加下一行:

    export SECRET_KEY_BASE=3aa7e349bh345h245hi23452345h234ih52i3u45h$
    export MATCH_PEOPLE_DATABASE_PASSWORD=your_pass_here

    # Uncomment these lines and restart the server to validate if the variables are read correctly
    #ruby -e 'p ENV["SECRET_KEY_BASE"]'
    #ruby -e 'p ENV["MATCH_PEOPLE_DATABASE_PASSWORD"]'

在以下文件的末尾:

  1. sudo nano ~/.bash_profile
  2. sudo nano/etc/environment

如果你愿意,你可以在 ~/.bash_profile 中取消最后两行的注释并重新启动你的服务器,当你再次登录时,您将在提示之前看到环境变量的值,如下图所示。

enter image description here

我建议您对这些行进行注释,只是为了验证,然后再次对它们进行注释。

如有任何问题,欢迎留言!

希望对你有用。

关于ruby-on-rails-4 - Rails 4 : How to add ENVIRONMENT VARIABLES on Ubuntu 14. 04 使用 RVM?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32961961/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com