Issue:
security.yml:
security: encoders: FOS\UserBundle\Model\UserInterface: sha512 role_hierarchy: ROLE_ADMIN: ROLE_USER ROLE_SUPER_ADMIN: [ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] providers: fos_userbundle: id: fos_user.user_provider.username_email firewalls: main: pattern: ^/ form_login: check_path: /login_check login_path: /login default_target_path: /profile provider: fos_userbundle logout: path: /logout target: /splash anonymous: ~ access_control: - { roles: ROLE_USER, requires_channel: https } - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https } acl: connection: default
Environment Architecture:
The Server1 and Server2 holds Symfony2 application.
Question:
How to force Symfony to generate redirect URL with https protocol instead http?
So far I have looked at these docs, and the solution didn't work work in my case:
Take a look at
vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Request.php
AWS ELB's use HTTP_X_FORWARDED_PROTO and HTTP_X_FORWARDED_PORT while Symfony looks the X_FORWARDED_PROTO and X_FORWARDED_PORT headers to judge the connection and its secure status.
You can try changing those keys in the trustedHeaders although I would not recommend directly changing them but finding a way to override those.
protected static $trustedHeaders = array( self::HEADER_CLIENT_IP => 'X_FORWARDED_FOR', self::HEADER_CLIENT_HOST => 'X_FORWARDED_HOST', self::HEADER_CLIENT_PROTO => 'HTTP_X_FORWARDED_PROTO', self::HEADER_CLIENT_PORT => 'HTTP_X_FORWARDED_PORT', );
Reference - http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/TerminologyandKeyConcepts.html#x-forwarded-for
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With