【问题标题】:Add one parameter to a Symfony firewall based on current host基于当前主机向 Symfony 防火墙添加一个参数
【发布时间】:2015-08-28 14:57:47
【问题描述】:

在生产服务器上部署我的网站(在 Symfony 2.7 上运行)之前,我会在开发服务器上进行(但也在prod 环境中)。因为我不想让任何人看到它,所以我想用一个简单的 HTTP 基本身份验证来保护它。

我看到我可以将host parameter 添加到防火墙,这样它只适用于站点在给定主机上运行的情况。看起来这可以帮助我,但据我了解,我必须复制我的防火墙,这不是那么有趣(DRY):

firewalls:
    main:
        host: www\.mysite\.com
        pattern: ^/
        form_login:
            // ...
        logout:
            // ...
        anonymous: true
        remember_me:
            key: %secret%

    main_dev:
        host: dev\.mysite\.com
        http_basic: true
        // paste here the exact same content as in `main`

是否有不涉及维护两个相同防火墙的解决方案?

【问题讨论】:

    标签: php security symfony basic-authentication


    【解决方案1】:

    我建议使用两个不同的配置文件,见:http://symfony.com/doc/current/cookbook/configuration/configuration_organization.html

    所以有一个 security.yml 和一个 security_dev.yml -> 你的所有阶段都使用 security.yml 并且只有在 dev 中你才会加载你的附加/不同参数。

    【讨论】:

    • 我忘了提到该站点在两台服务器上都运行在prod 环境中。对于那个很抱歉。我编辑了我的问题。
    • 但您仍然可以为 prod1 或 prod2 创建配置环境,例如,请参阅 symfony.com/doc/current/cookbook/configuration/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-27
    • 1970-01-01
    • 1970-01-01
    • 2015-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多