ruby-on-rails - 将多个子域指向同一个 heroku 应用程序

标签 ruby-on-rails heroku dns subdomain

我正在尝试为我的主应用创建子域,例如 blog.mysite.compodcast.mysite.com。我希望在我的博客和播客子域中轻松访问主应用程序中的一些资源。我还希望用户也能够登录这两个子域。因此,我将博客和播客构建到同一个主应用程序中,访问同一个数据库。这些子域是在我的路由文件中使用子域约束指定的,如下所示:

Rails.application.routes.draw do

  constraints subdomain: 'blog' do
    match '/', to: 'blog_posts#index', via: :get
    resources 'blog_posts', path: 'posts'
  end

  constraints subdomain: 'podcast' do
    match '/', to: 'podcasts#index', via: :get
    resources 'podcasts'
  end

  constraints subdomain: ['www', ''] do
    # my other resources
  end
end

现在一切都在本地工作了,我正在尝试使用 Heroku 和 DNSimple 正确配置它。我有一条从 mysite.com 指向 mysite.herokuapp.com 的 CNAME 记录,该记录在未添加子域时有效。我希望能够以类似的方式将 blog.mysite.com 指向 mysite.herokuapp.com,因为所有功能都基于正在提取的 URL。

但是,当我访问 blog.mysite.com 时,它似乎正确指向 mysite.herokuapp.com,但我收到一条消息说 Heroku 应用程序不存在。这对我来说没有意义,因为它本质上与我在本地运行的应用程序相同,它接受 blog 子域并按照我想要的方式工作。

最佳答案

when I visit blog.mysite.com, it seems to be properly pointing to mysite.herokuapp.com, but I receive a message saying the Heroku app doesn't exist.

该错误意味着您尚未在 Heroku 上配置域。请记住使用 domains:add command 在 Heroku 中添加 blog.mysite.com .

关于ruby-on-rails - 将多个子域指向同一个 heroku 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34548865/

相关文章:

html - 在 PDF 的封面上隐藏页眉/页脚

ruby-on-rails - Ruby on rails - Rack 中间件排除 - 可能吗?

java - 上下文路径与 webapp-runner 中的 Spring UrlTag 冲突?

node.js - 安装依赖项后如何清理 heroku 中的缓存?

scala - 主机级 akka-http 客户端连接的生存时间

dns - Behat + Mink 无法使用代理(DNS 无法解析域名)

ruby-on-rails - Rails远程表单成功,但没有返回数据

ruby-on-rails - Rails 中的常量值

ruby-on-rails - 在 Heroku Rails 4 上设置 PostgresQL

php - 正确匹配 IDN URL