您对如何配置开发/登台/生产实例的奇怪想法有何看法?

发布于 2024-07-10 11:43:13 字数 606 浏览 7 评论 0原文

我刚刚对如何配置与环境相关的参数有一个奇怪的想法。 您可以在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

对你的占有欲 2024-07-17 11:43:13

我不认为重写规则是放置此类配置信息的特别直观的地方。 也许我误解了一些东西,但是开发、登台和生产环境之间的唯一区别是数据库连接吗? 通常,代码也是不同的(至少进行一次更改),因此如果您使用修订控制系统,我认为最好有一个您复制的模板配置文件(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.

神经暖 2024-07-17 11:43:13

你是对的——这是一个奇怪的想法。

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.

美胚控场 2024-07-17 11:43:13

如果你想在虚拟主机中设置环境,你可以执行类似的操作

php_value ENV "development"

,然后从 $_SERVER 数组中读取它

If you want to set the environment in the vhost you can do something like

php_value ENV "development"

And then read it from the $_SERVER array

北陌 2024-07-17 11:43:13

首先,如果您实际上没有更改 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:

A dash indicates that no substitution
should be performed (the existing path
is passed through untouched). This is
used when a flag (see below) needs to
be applied without changing the path.

But really, I think the answer is mod_env. SetEnv directives could be placed within your <VirtualHost> blocks, avoiding the unnecessary RewriteRule foo.

冰魂雪魄 2024-07-17 11:43:13

定义当前环境的最佳且唯一的地方是 bootstrap。

查看 symfonyagavi 引导文件。

The best and only place where you should define current environment is bootstrap.

Look at symfony or agavi bootstrapping files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文