【问题标题】:How to set up two domains to point at the same app with Passenger but with different Rails functionality?如何设置两个域以指向具有Passenger但具有不同Rails功能的同一个应用程序?
【发布时间】:2015-03-03 00:51:39
【问题描述】:

我在 Apache 上有两个域:domain1.tld & domain2.tld

目前我有domain1.tld 与Passenger 完美合作,但我还需要domain2.tld 指向同一个应用程序,但是当它到达第二个域时,它将具有不同的功能(即调用不同的控制器并具有一些不同的路线)而不是当用户点击domain1.tld时。

您如何在 Rails 中进行传统配置?

就 Apache 配置而言,domain1.tld 有以下内容:

DocumentRoot /home/username/apps/domain1.tld/production/current/public
<Directory /home/username/apps/domain1.tld/production/current/public>
   AllowOverride all
   Options -MultiViews
   Require all granted
</Directory>

ErrorLog /home/username/logs/domain1.tld.error.log
CustomLog /home/username/logs/domain1.tld.access.log combined

对于 Apache 配置,domain2.tld 需要什么?

【问题讨论】:

    标签: ruby-on-rails ruby apache ruby-on-rails-4 passenger


    【解决方案1】:

    您的设置有时也可能演变为拥有两个完全独立的应用程序。我会让你更好地判断何时以及何时不需要。话虽如此,您可以使用 Rails 中的路由约束来实现您的要求。例如:(请注意,这不是实现这一目标的唯一方式,而是我的首选方式)

    root to: 'home#index1', as: :domain1, constraints: {|req| req.host == 'domain1.tld' }
    root to: 'home#index2', as: :domain2, constraints: {|req| req.host == 'domain2.tld'}
    root to: 'home#index'
    

    要添加新的 Apache 主机,需要添加另一台虚拟主机并指向与主应用程序相同的公用文件夹。因此,在这种情况下,只需创建与第一个配置文件中相同的所有信息,但只需添加 domain2.tld 作为新虚拟主机的名称。

    【讨论】:

    • 欣赏这个答案。由于您可能错过了有关 httpd 配置的部分,因此我已经澄清了我上面的问题,并详细说明了我当前的配置并直接标注了问题的另一部分。
    • 我不确定您是否可以在 Apache 级别上实现这一点。因为,调用适当的控制器操作的责任属于 Rails 堆栈而不是 Apache。
    • 嗯,这是一个双重问题。您对 rails 配置的建议是正确的,但 Apache 同样必须了解 domain2.tld
    • Apache 和 Rails 应用程序是在同一台服务器上还是在不同的服务器上?
    • 在这种情况下,Apache with Passenger 和 Rails 应用程序位于同一台服务器上。
    猜你喜欢
    • 1970-01-01
    • 2012-03-03
    • 1970-01-01
    • 1970-01-01
    • 2016-03-25
    • 2019-11-05
    • 1970-01-01
    • 2016-12-26
    • 1970-01-01
    相关资源
    最近更新 更多