强制https时在symfony2中重定向循环 [英] Redirect Loop in symfony2 when forcing https
问题描述
在我的Symfony2应用程序中,我设置了防火墙,以便/admin
路由下的所有内容都需要通过https运行,但是在部署时会出现重定向循环.我已经阅读了Symfony2网站上有关防火墙的文档,并设置了登录表单.我也阅读了一些Stack Overflow文章并尝试了解决方案,但到目前为止还没有.
In my Symfony2 app I have a firewall set up so that everything under the /admin
route needs to be run through https, however when deployed I get a redirect loop. I've read the documentation on the Symfony2 site on firewalls, and setting up a login form. I've also read a few Stack Overflow articles and attempted their solutions, but nothing so far.
下面是我的配置,我缺少什么吗?
Below is my configuration, is there something I'm missing?
(据我所知,服务器正在运行Apache,我无法从托管服务提供商直接访问服务器配置)
(As far as I know the server is running Apache, I've no direct access to server configuration from my hosting provider)
access_control:
# require ROLE_ADMIN for /admin*
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
- { path: ^/login_check, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
- { path: ^/admin*, roles: ROLE_ADMIN, requires_channel: https}
推荐答案
根据您自己的回答,您的网站似乎位于负载均衡器或反向代理的后面(因为您需要检查HTTP_X_FORWARDED_PROTO
服务器变量,通常是空的.
Based on your own answer, it seems your website is behind a Load Balancer or a Reverse Proxy (since you need to check on the HTTP_X_FORWARDED_PROTO
server variable, which is normally empty).
您的托管服务提供商可能已在您未明确了解的情况下进行了此类设置.默认情况下,Symfony会忽略X-Forwarded-Proto
和X-Forwarded-For
标头,除非您添加代理到app/config/config.yml
文件中的白名单:
Your hosting provider may have put such a setup in place without your explicit knowledge. By default, Symfony ignores the X-Forwarded-Proto
and X-Forwarded-For
headers, unless you add the proxy to a whitelist in your app/config/config.yml
file:
framework:
trusted_proxies: [127.0.0.1, ::1]
在其中127.0.0.1
和::1
应该替换为托管服务提供商使用的实际代理/代理(它们应该能够告诉您).
Where 127.0.0.1
and ::1
should be replaced by the actual proxy/proxies that your hosting provider uses (they should be able to tell you that).
这样做应该可以使其工作,而不会破坏app.php文件.
Doing that should make it work without hacking the app.php file.
这篇关于强制https时在symfony2中重定向循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!