您对如何配置开发/登台/生产实例的奇怪想法有何看法?
我刚刚对如何配置与环境相关的参数有一个奇怪的想法。 您可以在 Rails 的 config/database.yml 中找到类似的参数,
在我当前的项目中,我使用 PHP 和 Litespeed Web Server(尽管相同的技术适用于 PHP + Apache),并且我想......“为什么不使用 mod_rewrite这?'。 我为每个环境(目前是开发/生产)都有单独的虚拟主机配置,
我现在拥有的是:
RewriteRule (.*) $1 [env=development:1]
用于开发环境虚拟主机的 。 但如果是这样呢?
RewriteRule (.*) $1 [env=development:1,env=mysql_host:localhost,env=mysql_port:3306,env=mysql_user:root,env=mysql_pass:,env=mysql_db:mydbname]
它有意义还是会导致一些问题? 你怎么认为?
I just got a weird idea about how to configure environment-dependent parameters. Sort of like parameters you can find in Rails' config/database.yml
In my current project I use PHP and Litespeed Web Server (though the same technique applies to PHP + Apache), and I thought... 'why not use mod_rewrite for this?'. I have separate virtual hosts configs for each env (development/production at the moment)
What I have now is:
RewriteRule (.*) $1 [env=development:1]
for the development environment vhost. But what if it will be something like this?
RewriteRule (.*) $1 [env=development:1,env=mysql_host:localhost,env=mysql_port:3306,env=mysql_user:root,env=mysql_pass:,env=mysql_db:mydbname]
Would it make sense or will cause some problems? What do you think?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我不认为重写规则是放置此类配置信息的特别直观的地方。 也许我误解了一些东西,但是开发、登台和生产环境之间的唯一区别是数据库连接吗? 通常,代码也是不同的(至少进行一次更改),因此如果您使用修订控制系统,我认为最好有一个您复制的模板配置文件(database.cfg.template) (并告诉您的版本控制系统忽略)并修改(到database.cfg)。 那么这些信息在哪里就很明显了。
I don't believe rewrite rules are a particularly intuitive place to put configuration information like that. Maybe I am misunderstanding something, but is the only difference between the development, staging, and production environments the database connection? Typically the code is also different (at least once changes are made), and so if you are using a revision control system, I think it might be a better idea to have a template configuration file (database.cfg.template) that you copy (and tell your revision control system to ignore) and modify (to database.cfg). Then it's obvious where this information is.
你是对的——这是一个奇怪的想法。
IMO,这是 mod_rewrite 的一个非常糟糕的使用。 确实,配置信息属于机器,而不是代码库(我看到人们一直犯的错误),但它也不一定属于网络服务器配置。
我会推荐一个不受版本控制管理的配置文件。
You're right -- it's a wierd idea.
IMO, this is a really bad use for mod_rewrite. True, the configuration information belongs with the machine, rather than the codebase (a mistake I see people make all the time), but it doesn't necessarily belong with the webserver configuration, either.
I would recommend a configuration file that is not managed by version control.
如果你想在虚拟主机中设置环境,你可以执行类似的操作
,然后从
$_SERVER
数组中读取它If you want to set the environment in the vhost you can do something like
And then read it from the
$_SERVER
array首先,如果您实际上没有更改 URL,请不要使用 $1 作为替换,只需使用破折号即可。 根据文档:
但实际上,我认为答案是 mod_env。 SetEnv 指令可以放置在您的中。 块,避免不必要的 RewriteRule foo.
First of all, if you're not actually changing the URL, don't use $1 as the replacement, just use a dash. As per the docs:
But really, I think the answer is mod_env. SetEnv directives could be placed within your <VirtualHost> blocks, avoiding the unnecessary RewriteRule foo.
定义当前环境的最佳且唯一的地方是 bootstrap。
查看 symfony 或 agavi 引导文件。
The best and only place where you should define current environment is bootstrap.
Look at symfony or agavi bootstrapping files.