"require_channel:https"导致错误310,重定向太多

Stu*_*haw 5 symfony

如果我尝试强制我的网站的某些区域使用https我得到

Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.

如果我只是使用https://我自己的页面呈现正常,那只有当我强迫它使用https时.

这是我的security.yml,但如果我也使用注释,我会得到同样的错误.

security:
    encoders:
        FOS\UserBundle\Model\UserInterface: sha512

    role_hierarchy:
        ROLE_ADMIN:       ROLE_USER
        ROLE_MERCHANT:    ROLE_USER
        ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH, ROLE_MERCHANT]

    providers:
        fos_userbundle:
            id: fos_user.user_provider.username_email

    firewalls:
        dev:
            pattern:  ^/(_(profiler|wdt)|css|images|js)/
            security: false
        main:
            pattern: ^/
            form_login:
                provider: fos_userbundle
                csrf_provider: form.csrf_provider
                default_target_path: /dashboard
            logout:       true
            anonymous:    true

    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY}
        - { path: ^/login_check$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, role: ROLE_ADMIN, requires_channel: https }
        - { path: ^/dashboard, role: ROLE_USER, requires_channel: https}
        - { path: ^/invoice/new, role: ROLE_MERCHANT, requires_channel: https}
        - { path: ^/invoice, role: ROLE_USER, requires_channel: https}
Run Code Online (Sandbox Code Playgroud)

我正在使用nginx而不是Apache.

Rob*_*rto 2

尝试添加

fastcgi_param HTTPS on;
Run Code Online (Sandbox Code Playgroud)

对于您的 nginx 虚拟主机,这将帮助 Symfony 识别该请求是 SSL 请求,symfony 正在检查 HTTPS 全局变量以检查该请求是否是 SSL 并相应地重定向,如果该变量未由网络服务器内部设置SSL 请求 symfony 将尝试重定向导致循环:)

更多信息在这里.. http://blog.servergrove.com/2011/04/04/symfony2-quick-tip-generateurl-with-https-on-nginx/