使用 Symfony 强制使用 HTTPS [英] Forcing HTTPS with Symfony

查看:29
本文介绍了使用 Symfony 强制使用 HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试强制所有对 example.com/checkout/的请求使用 HTTPS.我阅读了 Symfony docs 并在我的 security.yml 文件中有这个:

I'm trying to force all requests to example.com/checkout/ to use HTTPS. I read the Symfony docs and have this in my security.yml file:

access_control:
    - { path: ^/checkout, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }

但是,当我转到 http://example.com/checkout/ 时,我没有被重定向到 HTTPS.我做错了什么?

However, when I go to http://example.com/checkout/, I am NOT redirected to HTTPS. What am I doing wrong?

推荐答案

原来我没有设置防火墙.我需要在 security.yml 的防火墙部分添加它:

Turns out I did not have a firewall setup. I needed to add this under the firewalls section of security.yml:

checkout:
    pattern: ^/checkout
    anonymous: ~

这奏效了:

access_control:
    - { path: ^/checkout, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }

这篇关于使用 Symfony 强制使用 HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆