【问题标题】:nginx + SslRequirement + mongrel cluster = infinite redirect loopnginx + SslRequirement + mongrel 集群 = 无限重定向循环
【发布时间】:2011-03-29 15:28:45
【问题描述】:

向我的网站添加 SSL 支持后,我得到了一个无限重定向循环。我正在使用“SslRequirement”插件。

我看到的症状是,任何启用了“ssl_required”的操作,以及我手动输入的任何前面有 https 的 URL,都会进入无限循环,在 development.log 文件中有以下内容,一遍又一遍,直到浏览器捕捉到重定向循环并停止加载页面(“/admins/index”是本示例中的操作,但它发生在任何操作中):

Processing AdminsController#index (for 127.0.0.1 at 2010-08-13 13:50:16) [GET]
  Parameters: {"action"=>"index", "controller"=>"admins"}
Redirected to https://localhost/admins
Filter chain halted as [:ensure_proper_protocol] rendered_or_redirected.
Completed in 0ms (DB: 0) | 302 Found [http://localhost/admins]

起初我认为存在某种问题,我必须将所有操作都设为“ssl_allowed” - 所以我尝试了,但无济于事。

如果我删除了 SslRequirement 的使用,并删除了所有“ssl_required/ssl_allowed”引用,那么 https 工作正常 - 所以问题似乎是从 http 到 https 的操作重定向。

有什么线索吗?

【问题讨论】:

    标签: ssl nginx mongrel-cluster


    【解决方案1】:

    在这里找到答案:

    http://www.hostingrails.com/SSL-Redirecting-not-working

    短版是,我在我的 nginx 配置中的 SSL vhost 中添加了以下行:

    proxy_set_header X_FORWARDED_PROTO https;


    详细版本是:

    基本上问题归结为 nginx 服务器没有将源请求是 HTTPS 协议这一事实传递到 Mongrel 集群。这导致调用“request.ssl?”在 SslRequirement 插件中总是返回 false。

    因此,当它返回为 false 时,“ensure_proper_protocol”将通过 https 重新发出操作,这将检查“request.ssl?”,这将返回“false”,这将通过 https 重新发出操作,它将检查“request.ssl?”,它将返回“false”,它将通过https重新发出操作,它将检查“request.ssl?”,它将返回“false”,它将重新发出在 https 上的操作,将检查“request.ssl?”,这将返回“false”,这将通过 https 重新发出操作 ...

    ...你明白了。 mongrel 集群从不认为请求是通过 HTTPS 协议进行的,因此它永远重定向。 nginx 配置中的一个小改动来纠正这个问题,BAM-O:问题解决了。

    【讨论】:

      猜你喜欢
      • 2019-08-31
      • 2023-03-19
      • 2011-06-04
      • 2021-10-21
      • 2020-09-22
      • 1970-01-01
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多