如何在一个域(和子域)上提供多个 Rails 应用程序?

发布于 2024-10-09 08:46:21 字数 789 浏览 0 评论 0原文

这有点奇怪,但我想在同一域上提供多个网站。如果可能的话,我们希望避免使用子域,以使用户的网址保持简单 - 他们不需要知道这是两个单独的应用程序。这纯粹是为了保持代码库分离。有什么想法吗?

例如:

Rails 应用程序 1 (Refinery CMS) 提供:

http://example.com/

http://example.com/about

http ://example.com/pricing

Rails App 2(我们真正的应用程序)提供:

http://example.com /account

http://example.com/store

http://example.com/listings

我们使用 ruby​​ 1.9.2、ruby on Rails、refinery cms、apache 和乘客。

This is kind of weird but I'd like to serve multiple websites on the same domain. If possible, we want to avoid subdomains to keep urls simple for our users - no need for them to know it's two separate apps. This is purely for keeping the code bases separate. Any ideas?

For example:

Rails App 1 (Refinery CMS) serves:

http://example.com/

http://example.com/about

http://example.com/pricing

Rails App 2 (our real App) serves:

http://example.com/account

http://example.com/store

http://example.com/listings

We use ruby 1.9.2, ruby on rails, refinery cms, apache and passenger.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

南渊 2024-10-16 08:46:21

如果您使用的是 Passenger,请查看部署到子 URI 部分 - 在子 URI 上设置应用程序非常简单。您可能还需要在应用配置中设置config.action_controller.relative_url_root

编辑:我误读了这个问题;不是每个 URI 一个应用程序,而是一个应用程序为某些(但不是全部)端点提供服务。实际上,通过一些基本的重写也可以很容易地做到这一点。

假设将 Rails 应用部署到 /railsapp(但不设置 relative_url_root)。现在,在 .htaccess 中:

RewriteRule ^account/(.*)$ railsapp/account/$1 [L]

这将在内部将 /account/* 重新映射到 /railsapp/account/*,因此只要您为 Rails 应用程序处理的每个路径设置重写,它就应该可以正常工作。

If you're using Passenger, check out the Deploying to a sub URI portion of the manual - it's quite simple to set up an app on a sub-URI. You may need to set config.action_controller.relative_url_root in your app configuration, as well.

Edit: I misread the question; not one app per URI, but one app serving some (but not all) endpoints. This is actually moderately easy to do with some basic rewrites, as well.

Deploy your Rails app to, let's say, /railsapp (but without setting relative_url_root). Now, in .htaccess:

RewriteRule ^account/(.*)$ railsapp/account/$1 [L]

This will internally remap /account/* to /railsapp/account/*, so as long as you set up a rewrite per path your Rails app handles, it should work fine.

逆光下的微笑 2024-10-16 08:46:21

子域使其变得更容易(这就是为什么大多数站点都有 shop.example.com),但您可能可以使用基于名称的虚拟主机路由的重写规则。我不确定具体该怎么做。更多关于超级用户的 Apache 重写问题。

警告如果您使用 SSL,可能会出现问题。

Subdomains make it easier (thus why most sites have shop.example.com), but you could probably use rewrite rules with name based virtual host routing. How exactly to do that I'm not sure. More of a Apache rewrite question for SuperUser.

A word of warning if you are using SSL you might have issues arise.

演出会有结束 2024-10-16 08:46:21

您可以将其设置为首先点击一个您希望大多数 URL 都可以工作的应用程序,如果出现 404 错误,您可以指示它接下来尝试另一个应用程序,尽管这会比按路由进行路由慢,但它无需硬编码即可工作。在 Refinery CMS 上创建的每个页面的路由。

You could set it up to first hit one app where you expect most URLs would work and if it 404s you could instruct it to try the other app next, though this will be slower than routing per route but it will work without having to hardcode a route for every page that is created on say, Refinery CMS.

无可置疑 2024-10-16 08:46:21

目前我也在开发同类型的 CMS。就我而言,我还需要多个子域,例如

www.test1.mydomain.com

www.test2.mydomain.com

www.test3.mydomain.com

www.test4.mydomain.com

这是我

在rails 3中所做的(如果你在rails3)上,您可以使用请求对象获取子域。 (如果您使用的是 Rails 2.x,则可以使用 sub domain_fu 插件)

在我的例子中,我使用了 before 过滤器来获取子域,之后我根据子域加载站点

对于开发,请使用以下公共域“ lvh.me"

http://tbaggery.com/2010/03 /04/smack-a-ho-st.html

这对我来说非常有用 http://railscasts.com/episodes/221-subdomains-in-rails-3

让用户将其域转发到您的子域(带屏蔽),

例如:www.clientdomain.com --> http://client.mydomain.com

希望这有助于

欢呼

为Sameera

Currently I'm also working on a same kind of CMS. In my case also I need multiple sub domains, like

www.test1.mydomain.com

www.test2.mydomain.com

www.test3.mydomain.com

www.test4.mydomain.com

here is what I did

in rails 3 (if you are on rails3) you can get the sub domain by using request object. (If you are on rails 2.x you can use sub domain_fu plugin)

In my case I have used a before filter to get the sub domain, after that I load the site according to the sub domain

For development use the following public domain "lvh.me"

http://tbaggery.com/2010/03/04/smack-a-ho-st.html

this was very useful for me http://railscasts.com/episodes/221-subdomains-in-rails-3

let users have their domains forwarded to your subdomain (with masking)

ex : www.clientdomain.com --> http://client.mydomain.com

hope this helps

cheers

sameera

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