在 Symfony 中,如何在开发环境中要求 http 而在生产环境中要求 https? [英] In Symfony, how can I require http in a dev environment and https in production?

查看:19
本文介绍了在 Symfony 中,如何在开发环境中要求 http 而在生产环境中要求 https?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在生产中,我有一组需要 SSL 的路由,但这不应该是开发的要求.

In production, I have a group of routes that require SSL however this shouldn't be a requirement for development.

我认为我可以简单地覆盖 routing_dev.yml 中的路由,但这似乎不起作用.导航到任何路线时,它会强制使用 https.

I thought that I could simply override my routes in routing_dev.yml but that doesn't seem to work. When navigating to any route, it forces https.

我的设置:

  • app/config/routing_dev.yml 包含一系列路由,复制自 src/FOO/FOOBarBundle/Resources/config/routing,没有 schemes: [https]
  • src/FOO/FOOBarBundle/Resources/config/routing.yml 包含与上述相同的schemes:[https]
  • app/config/routing_dev.yml contains a series of routes, duplicated from src/FOO/FOOBarBundle/Resources/config/routing, without schemes: [https]
  • src/FOO/FOOBarBundle/Resources/config/routing.yml contains the same as above just with schemes: [https]

我预计 routing_dev.yml 中的路由会先于包中的路由,并且会在开发中使用.

I expected that the routes in routing_dev.yml would have preceded those in the bundle and would have been the ones used while in development.

我是否走在正确的道路上,或者是否有更好的方法来为选定的一组路由在开发中实现 http 和在生产中实现 https?

Am I on the right path, or is there a better way of accomplishing http in development and https in production for a select group of routes?

推荐答案

开发环境需要使用src/FOO/FOOBarBundle/Resources/config/routing_dev.yml(在app/config/routing_dev.yml 而不是导入 src/FOO/FOOBarBundle/Resources/config/routing.yml)

You need to use src/FOO/FOOBarBundle/Resources/config/routing_dev.yml for dev-environment (import it in app/config/routing_dev.yml instead of importing src/FOO/FOOBarBundle/Resources/config/routing.yml)

这篇关于在 Symfony 中,如何在开发环境中要求 http 而在生产环境中要求 https?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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