如何强制https为prod但http为dev环境? [英] How to force https for prod but http for dev environment?

查看:211
本文介绍了如何强制https为prod但http为dev环境?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个symfony2应用程序。

I have a symfony2 application.

在prod服务器上我希望我的所有路由都通过https进行,而在dev中我希望能够使用http。我如何单独使用symfony2实现这一目标?我不想触摸网络服务器配置。

On the prod server I want all my routes to go via https, while in dev I want to be able to use http. How do I achieve that with symfony2 alone? I do not want to touch the webserver configuration.

我尝试在我的 routing.yml

I tried adding this in my routing.yml

myBundle:
    resource: "@MyBundle/Controller/"
    type:     annotation
    prefix:   /
    schemes:  [https]

在我的 routing_dev中有这个.yml

myBundle:
    resource: "@MyBundle/Controller/"
    type:     annotation
    prefix:   /
    schemes:  [http]

_main:
    resource: routing.yml

即使在开发模式下它仍然想要转到https。

It still wants to go to https even in dev mode.

推荐答案

您可以为此定义参数。在 app / config / config.yml define:

You can define parameter for that. In app/config/config.yml define:

parameters:
    httpProtocol: http

然后在 app / config / config_prod.yml

parameters:
    httpProtocol: https

并在 routing.yml 更改为:

myBundle:
    resource: "@MyBundle/Controller/"
    type:     annotation
    prefix:   /
    schemes:  ['%httpProtocol%']

清除缓存(prod和dev),它应该可以工作。

Clear the cache (both prod and dev) and it should work.

这篇关于如何强制https为prod但http为dev环境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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