如何在基于域或子域的 ColdFusion 中的同一代码库上运行多个站点
我有一个 ColdFusion 应用程序。我希望能够针对多个域或子域运行相同的代码库(而不是重复它)。每个网站本质上都是相同的,只是它们有品牌、皮肤和不同的标题等。
所以,我正在寻找的是如何拥有:www.abc.com 和 www.xyz.com 以及beta.mycompany.com 都运行相同的代码库。理想情况下,当新客户登录时,可以快速添加新域。
我见过 PHP 和 Rails 的这个问题,但没有见过 CF。这是我的想法(它似乎有效),但想知道是否会出现性能问题或更清晰的建议。
应用中.CFC
<cfif cgi.server_name EQ "www.abc.com" >
<cfset request.client_id=1>
<cfelseif cgi.server_name EQ "www.xyz.com">
<cfset request.client_id=2>
... etc
<cfelse>
This application not configured.
<cfabort>
</cfif>
现在,只需关闭 client_id 的所有内容...
I have a ColdFusion application. I would like to be able to run the same codebase (rather than duplicate it) against multiple domains or subdomains. Each of the sites would be essentially the same, except that they would be branded, skinned and have different titles, etc.
So, what I'm looking for is how to have: www.abc.com and www.xyz.com and beta.mycompany.com all running off same codebase. Ideally, it will be quick to add new domains as new clients sign on.
I've seen this question for PHP and Rails, but not CF. Here is what I was thinking (and it seems to work), but was wondering if there are would be performance issues or a cleaner suggestion.
IN APPLICATION.CFC
<cfif cgi.server_name EQ "www.abc.com" >
<cfset request.client_id=1>
<cfelseif cgi.server_name EQ "www.xyz.com">
<cfset request.client_id=2>
... etc
<cfelse>
This application not configured.
<cfabort>
</cfif>
Now, just key everything off client_id...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
应用程序实例基于 Application.name,
因此您只需以不同的方式命名每个实例
。在 application.cfc 中,您可以有类似这样的内容
。现在每个域都会产生不同的应用程序名称,从而将实例和应用程序变量集等分开。
The application instance is based on the Application.name
so you just name each instance differently
In application.cfc you can have something like this
Each domain now causes a different application name, thus separate instance and sets of application variables etc.
我做了类似的事情,但我将所有信息保存在数据库中。这使得添加新网站变得更加容易,并且不需要为每个新客户端或模板更改任何代码。
这是我来自 application.cfc 的代码:
现在我有一个应用程序配置为响应的网站集合。每个站点都会加载其模板。模板也保存在数据库中,因此每个站点都可以轻松配置为任何模板。
对于每个请求,我们只需要找到正确的网站:
现在每个请求都有可用的网站和模板。
我使用它来运行 3 个电子商务网站,其中包含一个代码库和数据库的 3 个不同模板。
I do something similar, but I keep all the info in a database. That makes it much easier to add new websites, and doesn't require any code changes for each new client or template.
Heres my code from application.cfc:
Now I have a collection of websites the application is configured to respond to. Each site loads its template. The templates are also saved in the database, so each site can be easily configured to any template.
For each request, we just need to find the correct website:
Now each request has the website and template available througout.
I'm use this to run 3 ecommerce sites with 3 different templates off one codebase and database.
是的,那会起作用。我将其放入我的 Application.cfc 中。我用它来为 DEV 和 PROD 设置不同的应用程序变量。
应用程序.cfc:
Yes, that would work. I throw it into my Application.cfc. I used this to set different Application variables for DEV and PROD.
Application.cfc: