在Rails应用程序中将多个域名映射到不同的资源 [英] Mapping multiple domain names to different resources in a Rails app

查看:94
本文介绍了在Rails应用程序中将多个域名映射到不同的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拥有的Rails应用程序允许用户管理度假屋.每个属性都有自己的 我的应用程序中的网站/首页",用户可以调整内容,效果很好, 到目前为止非常满意.典型的Rails会访问资源,因此特定属性的URL类似于特定属性的首页".

The rails app I have allows users to manage holiday homes. Each property has it's own "website/homepage" within my app and a user can tweak the content, it works well, quite pleased so far. Typical rails approach to the resources so the URLs to a particular property look like this for the "homepage" of a particular property.

localhost:3000/properties/1/

然后

localhost:3000/properties/1/full_details
localhost:3000/properties/1/price_list

要求是映射域名,例如www.chalet-yeti.com并将其解析(重写?)到localhost:3000/properties/1/

Requirement is to map a domain name e.g. www.chalet-yeti.com and have it resolve (rewrite?) to localhost:3000/properties/1/

也是如此...

www.chalet-yeti.com/full_details  -> localhost:3000/properties/1/full_details

下一个用户添加一个属性,我代表他们注册一个新名称,我当然想这样做.

The next user adds a property and I register a new name on their behalf and I'd like to do this of course..

www.apartment-marie.com  -> localhost:3000/properties/2/

在同一个Rails应用程序中是否可行/建议/可行?到目前为止,解决方案的范围从您为什么要这样做"到使用mod_proxy/mod_rewrite/virtual_host配置"的变体.以防万一,该应用程序可以在我的服务器上以apache和passenger运行.

Is this possible/advisable/doable in the same rails app? So far solutions have ranged from "why would you do that" to variations on "use mod_proxy / mod_rewrite / virtual_host config". In case it matters the app runs under apache and passenger on my server.

我不想抢先回答,但到目前为止,大多数人似乎都指向apache配置,并且大多数人说我正在尝试的事情并非不可能/不建议这样做.我真的希望有人至少可以在我整个上午抓挠时指出正确的方向.在这里,我希望离开我的舒适区,希望我可以启动我的应用程序,而且还没有花六个星期的时间就建造出白色大象!除非我可以执行此URL操作,否则它就死定了!

I don't want to pre-empt an answer but most people so far seem to point to apache configuration and most say what I'm attempting is not impossible / inadvisable. Really hope someone could at least point me in the right direction as I've been head scratching all morning. Out of my comfort zone here and I'm hoping I can launch my app and haven't spent six weeks building a white elephant! Unless I can do this URL thing, it's dead!

推荐答案

这就是您想要的.为此,请不要与Apache混为一谈.它无法扩展到数百个域,并且容易损坏.

This is what you want. Don't mess with apache for that. It doesn't scale to hundreds of domains and it's prone to breakage.

这篇关于在Rails应用程序中将多个域名映射到不同的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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