Symfony2:getScheme不返回'https' [英] Symfony2: getScheme does not return 'https'

查看:264
本文介绍了Symfony2:getScheme不返回'https'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

From within a controller, I have been using the method getSchemeAndHttpHost in order to build the url of another controller.

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

Everything has been running smoothly, until I needed to go over https. All urls that I get with the getSchemeAndHttpHost function are still http. Doing some troubleshooting, it came out that the getScheme function always returns http, both when I request the page with https and with http.

我错过了什么吗?

我怎么知道我的控制器是否超过http或https?

How can I know if I am over http or https from my controller ?

编辑 - 更多信息


  1. 我确保使用有效证书运行测试。

  2. 如果我在Request对象中运行isSecure方法,总是得到假。


推荐答案

简短回答

在控制器中添加以下行:

Add the following line in the controller:

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

更多细节

经过一些调查,我发现这与Proxies有关...
如果我们检查isSecure功能在做什么,我们会发现这个请求方法 isFromTrustedProxy 被调用以决定是否应返回true或false。

After some investigations, I discovered that this has to do with Proxies... If we check what the isSecure function is doing, we find this: the Request method isFromTrustedProxy is called to decide if true or false should be returned.

一旦我们知道该问题与代理有关,symfony文档将详细解释我们应该做些什么来信任代理如何管理负载均衡器或反向代理。在我的情况下,当我使用heroku时,信任传入的ip 是可行的方法。

Once we know the issue has to do with proxies, the symfony documentation explains in details what we should do to trust proxies or how to manage a load balancer or a reverse proxy. In my case, as I am working with heroku, trusting the incoming ip was the way to go.

这篇关于Symfony2:getScheme不返回'https'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆