2017-10-17 86 views
2

我想讓https爲我的rails應用程序工作。當我嘗試在應用程序上執行任何與帖子相關的活動時,我收到以下錯誤消息。HTTPS for Rails應用程序 - InvalidAuthenticityToken

Exception `ActionController::InvalidAuthenticityToken' at /usr/local/rvm/gems/ruby-2.4.1/gems/actionpack-5.0.4/lib/action_controller/metal/request_forgery_protection.rb:195 - ActionCon 
troller::InvalidAuthenticityToken 
Exception `ActionController::InvalidAuthenticityToken' at /usr/local/rvm/gems/ruby-2.4.1/gems/actionpack-5.0.4/lib/action_controller/metal/rescue.rb:23 - ActionController::InvalidAuthe 
nticityToken 
Exception `ActionController::InvalidAuthenticityToken' at /usr/local/rvm/gems/ruby-2.4.1/gems/activesupport-5.0.4/lib/active_support/notifications/instrumenter.rb:25 - ActionController 
::InvalidAuthenticityToken 
Exception `ActionController::InvalidAuthenticityToken' at /usr/local/rvm/gems/ruby-2.4.1/gems/actionpack-5.0.4/lib/action_dispatch/middleware/callbacks.rb:42 - ActionController::Invali 
dAuthenticityToken 
Exception `ActionController::InvalidAuthenticityToken' at /usr/local/rvm/gems/ruby-2.4.1/gems/actionpack-5.0.4/lib/action_dispatch/middleware/debug_exceptions.rb:77 - ActionController: 
:InvalidAuthenticityToken 
+0

你可以發佈你的控制器代碼的副本嗎?你是否在使用任何認證寶石,如Devise?如果是這樣,哪個版本?另外,這項工作沒有SSL嗎? –

+0

@TomAranda它適用於http。當我發佈其發佈到http表單提交從https –

+0

您的整個會話在https上?換句話說,您的所有請求是否加載表單GET並通過https發佈表單?如果不是,那麼rails可能會使用不同的會話,導致真實性令牌失敗。 –

回答

2

嘗試添加以下內容到config/environments/production.rb

# config/environments/production.rb 
Rails.application.configure do 
    config.force_ssl = true 
end 

如果你想這纔會在其他環境影響,將其添加到 適當的環境文件中。

+0

讓我測試一下:) –

+0

真棒這個作品。不得不添加'proxy_set_header X-Forwarded-Proto $ scheme;'在nginx配置以及:) –

+0

我很高興它的工作。 –

相關問題