部署时的ActiveSupport :: MessageEncryptor:资产:预编译

时间:2018-08-28 14:01:44

标签: ruby-on-rails deployment capistrano

我在将Rails应用程序部署到服务器时遇到问题。 当我尝试在步骤deploy:assets:precompile中进行部署时,我得到

 01 rake aborted!
  01 ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
  01 /var/www/spycommerce/shared/bundle/ruby/2.5.0/gems/activesupport-5.2.1/lib/active_support/message_encryptor.rb:206:in `rescue in _decrypt'
  ...
  01
  01 Caused by:
  01 OpenSSL::Cipher::CipherError:
  01 /var/www/spycommerce/shared/bundle/ruby/2.5.0/gems/activesupport-5.2.1/lib/active_support/message_encryptor.rb:201:in `final'
  ...

当我尝试编译资产手册RAILS_ENV=production bundle exec rake assets:precompile时,我不会出错

Capfile

# Load DSL and Setup Up Stages
require 'capistrano/setup'
require 'capistrano/deploy'

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

require 'capistrano/rails'
require 'capistrano/bundler'
require 'capistrano/rvm'
require 'capistrano/puma'

install_plugin Capistrano::Puma  # Default puma tasks

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

版本

rails -v => 5.2.1
capistrano -v => 3.11

我尝试修复config.require_master_key = true,并在deploy.rb中创建链接set :linked_files, %w{config/master.key}。没有帮助

1 个答案:

答案 0 :(得分:0)

从命令行测试Rails Api应用程序的MessageEncryptor时遇到了类似的问题。防止InvalidMessage异常的解决方案:如果必须在rails初始化上下文之外使用ActiveSupport :: MessageEncryptor,请手动设置ActiveSupport :: MessageEncryptor.use_authenticated_message_encryption = true。然后,MessageEncryptor使用预期的default_cipher aes-256-gcm。