Devise在生产/暂存环境下仅抛出401未经授权并重定向。

4

我已经使用Devise设置了一个认证系统。

在开发模式下,我可以成功登录,但是在staging/production环境中,即使使用有效的凭据,我也无法登录用户。

会话存储是否可能是原因?

这是我在config/initializers/session_store.rb文件中的内容:

# Be sure to restart your server when you modify this file.

Rails.application.config.session_store :cookie_store, key: '_pigo_session'

我还在config/intitializers/devise.rb文件中添加了config.http_authenticatable = false

我的staging.log文件如下:

  I, [2015-06-10T16:57:20.325304 #3577]  INFO -- : Started GET "/" for 69.59.28.19 at 2015-06-10 16:57:20 +0400
  I, [2015-06-10T16:57:20.327106 #3577]  INFO -- : Processing by OffersController#index as HTML
  I, [2015-06-10T16:57:20.328034 #3577]  INFO -- : Filter chain halted as #<Proc:0x007fad7d18c5b8@/home/deploy/apps/pigo/shared/bundle/ruby/2.1.0/gems/actionpack-4.1.4/lib/action_controller/metal/http_authentication.rb:71> rendered or redirected
  I, [2015-06-10T16:57:20.328232 #3577]  INFO -- : Completed 401 Unauthorized in 1ms (ActiveRecord: 0.0ms)

当你说你“无法”登录时,日志中是否出现任何错误或相关信息? - coding addicted
你是否在“after_sign_in_path_for”方法中错误地使用了静态路径而不是相对路径? - TarunJadhwani
@codingaddicted 我在我的问题中编辑了分段日志输出。 - Bogdan Popa
@TarunJadhwani 我没有覆盖那个方法。 - Bogdan Popa
我暂时没有想法,但是有类似的问题可能会对你有所帮助:https://dev59.com/qnfZa4cB1Zd3GeqPTJPJ https://dev59.com/1HPYa4cB1Zd3GeqPdwDQ - coding addicted
@codingaddicted 我已经尝试了https://dev59.com/qnfZa4cB1Zd3GeqPTJPJ#24885909,但在暂存环境中仍然无法工作。此外,在开发过程中,当尝试登录时,我会收到ActionController :: InvalidAuthenticityToken的错误提示。 - Bogdan Popa
1个回答

0
如果有人需要帮助,我最近也遇到了类似的问题。问题出在nginx配置上(在我的生产环境中作为反向代理使用)。
以下是我所更改的内容,以解决这个问题:
upstream puma {
  server localhost:3000;
}

server {
  # ...
  location @puma {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme; # <== added this line
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://puma;
  }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接