首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >symfony 3强制https时重定向过多

symfony 3强制https时重定向过多
EN

Stack Overflow用户
提问于 2016-08-06 10:57:48
回答 1查看 5.1K关注 0票数 18

我有一个类似于在SO上发布的其他问题的问题,但这些解决方案都没有奏效。

我使用的是内置到OSX El Capitan Server中的Apache,当我不通过以下指令将http流量强制到https上时,https工作得很好:

代码语言:javascript
复制
    access_control:
    - { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https, host: mypc\.local$ }

但是当访问我的网站的本地uri时,添加此命令会导致太多重定向错误:https://mypc.local/myproject/web/

完整的security.yml

代码语言:javascript
复制
security:
  access_control:
    - { path: ^/, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https, host: mypc\.local$ }

  providers:
    our_db_provider:
        entity:
            class: AppBundle:Users
            property: username

  encoders:
    AppBundle\Entity\Users: plaintext   

firewalls:
    # disable authentication for assets and the profiler 
    dev:
        pattern: ^/(_(profiler|wdt)|css|images|js)/
        security: false

    main:
        pattern:    ^/
        http_basic: ~
        provider: our_db_provider

        anonymous: ~
        form_login:
            login_path: /
            check_path: login

        logout:
            path:   /logout
            target: /
            invalidate_session: true 

编辑:以下是响应头部:

代码语言:javascript
复制
> GET /myproject/web/ HTTP/1.1
> Host: mypc.local
> User-Agent: curl/7.43.0
> Accept: */*
> 
< HTTP/1.1 301 Moved Permanently
< Date: Tue, 09 Aug 2016 12:15:00 GMT
< Server: Apache
< X-Powered-By: PHP/5.5.31
< Cache-Control: no-cache
< Location: https://mypc.local/myproject/web/
< MS-Author-Via: DAV
< Content-Length: 396
< Content-Type: text/html; charset=UTF-8
< 
* Ignoring the response-body
* Connection #0 to host mypc.local left intact
* Issue another request to this URL: 'https://mypc.local/myproject/web/'
* Found bundle for host mypc.local: 0x7f89b2d01780
* Re-using existing connection! (#0) with host mypc.local
* Connected to mypc.local (fe80::ea06:88ff:fecf:61c6) port 443 (#0)
> GET /myproject/web/ HTTP/1.1
.... repeated 20 times
EN

回答 1

Stack Overflow用户

发布于 2016-08-26 01:00:56

我在使用Symfony behing ELB和Beanstalk时也遇到了同样的问题。由UrlGenerator where生成的所有urls,使用http方案。强制使用https会让我的Symfony感到困惑,并运行无限重定向循环。

这与trusted_proxies变量有关。我认为symfony在做一个无限循环,因为对他来说,即使你使用https,你的方案也是http。

你的背后是一个清漆代理,一个负载均衡器?

对于我来说,使用totas的this answer解决了这个问题:

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

我不得不这样做,因为AWS ELB拥有动态IP。如果您的代理或负载均衡器有固定的IP,您可以按照解释的in symfony documentation使用truted_proxies变量。

如果有人在AWS ELB环境中有更好的解决方案,我很感兴趣。

我希望这能对你有所帮助。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38800127

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档