【问题标题】:Symfony2: getScheme does not return 'https'Symfony2:getScheme 不返回“https”
【发布时间】:2016-01-30 21:21:51
【问题描述】:

在一个控制器中,我一直在使用 getSchemeAndHttpHost 方法来构建另一个控制器的 url。

一切都很顺利,直到我需要通过 https。我使用 getSchemeAndHttpHost 函数获得的所有 url 仍然是 http。做了一些故障排除,结果发现 getScheme 函数总是返回 http,无论是当我使用 https 和 http 请求页面时。

我错过了什么吗?

我如何知道我的控制器是通过 http 还是 https ?

编辑 - 更多信息

  1. 我确保使用有效证书运行测试。
  2. 如果我在我的 Request 对象中运行 isSecure 方法,我总是会得到错误。

【问题讨论】:

  • 如果你有http,那就说明Request srevice的isSecure()方法返回false,你能测试一下吗? $request->isSecure().
  • isSecure 返回... False。我离开了我的无效证书,并且有了一个有效的证书,我仍然得到 $request->isSecure() 来返回 false。我很困惑。

标签: symfony https reverse-proxy


【解决方案1】:

简答

在控制器中添加以下行:

Request::setTrustedProxies(array($request->server->get('REMOTE_ADDR')));

更多细节

经过一番调查,我发现这与代理有关... 如果我们检查 isSecure 函数在做什么,我们会发现 thisRequest 方法 isFromTrustedProxy 被调用来决定应该返回 true 还是 false。

一旦我们知道问题与代理有关,symfony 文档就会详细解释what we should do to trust proxieshow to manage a load balancer or a reverse proxy。就我而言,当我与 heroku 合作时,trusting the incoming ip 是要走的路。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-31
    • 1970-01-01
    • 2014-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多