ELB 后面的 Symfony2 重定向到 http 而不是 https

编程入门 行业动态 更新时间:2024-10-27 02:19:41
本文介绍了ELB 后面的 Symfony2 重定向到 http 而不是 https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

问题:

  • 用户使用

解决方案

看一看

vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/Request.php

AWS ELB 使用 HTTP_X_FORWARDED_PROTO 和 HTTP_X_FORWARDED_PORT 而 Symfony 查看 X_FORWARDED_PROTO 和 X_FORWARDED_PORT 标头来判断连接及其安全状态.

您可以尝试更改 trustHeaders 中的那些键,尽管我不建议直接更改它们,而是找到一种方法来覆盖它们.

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',);

参考 -docs.aws.amazon/ElasticLoadBalancing/latest/DeveloperGuide/TerminologyandKeyConcepts.html#x-forwarded-for

Issue:

  • User logs in with example/login
  • Authentication is approved
  • As configured in security.yml Symfony2 redirects user to profile page after login.
  • But it redirects them to the wrong url example/homepage

security.yml:

security: encoders: FOSUserBundleModelUserInterface: 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:

  • symfony/doc/current/cookbook/routing/scheme.html

解决方案

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 - docs.aws.amazon/ElasticLoadBalancing/latest/DeveloperGuide/TerminologyandKeyConcepts.html#x-forwarded-for

更多推荐

ELB 后面的 Symfony2 重定向到 http 而不是 https

本文发布于:2023-11-01 19:47:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550240.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:而不是   重定向   ELB   http   https

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!