单个域上的多个Heroku应用程序 [英] Multiple Heroku apps on a single domain
问题描述
我很确定这个答案是不可能的,但我想我会再次检查一次: 我正在迁移一些Rails应用程序到Heroku。他们现在组织起来的方式是URL:
全部到目前为止,我读过的文章说这在Heroku上是不可能的:每个应用程序必须拥有自己的子域(例如site1.example.com,site2.example.com)。
我的客户不想更改URL结构(实际上可能会有一些参数;我已经阅读了多个说明路径与子域名对SEO更好的源代码)。
我是否正确地认为在Heroku上 ?
方案使用Rack Reverse Proxy的Heroku和Rails可以实现这一功能。我目前正在分别在/ blog和/ kb上运行一个WordPress博客和知识库。对于搜索引擎优化的目的,我不希望他们在一个子域。
Rails配置
添加到Gemfile:
gemrack-reverse-proxy,:require => rack / reverse_proxy
现在我们要将/ blog和/ blog /定向到Wordpress实例来自Rails应用程序。
在运行应用程序之前将其添加到您的config.ru中:
使用Rack :: ReverseProxy do
reverse_proxy(/ ^ \ / blog(\ /.*)$/,
'http://CHANGEME.herokuapp.com $ 1',
opts = {:preserve_host => true})
end
<在config / routes.rb中添加一条路线:
match/ blog=>重定向(/ blog /),通过::all
I'm pretty sure the answer to this is "not possible", but I thought I would check one last time:
I'm migrating some Rails apps to Heroku. The way they are organized now, URL-wise, is:
- http://example.com/site1 -- is served by app1
- http://example.com/site2 -- is served by app2
Everything I've read so far says this isn't possible on Heroku: that each application must have its own subdomain (e.g. site1.example.com, site2.example.com).
My client does not want to change the URL structure (and actually there may be some argument for that; I've read several sources that say that paths vs. subdomains is better for SEO).
Am I correct that this is not possible on Heroku?
This IS possible with Heroku and Rails using Rack Reverse Proxy. I'm currently doing it to run a Wordpress blog and knowledge base at /blog and /kb respectively. For SEO purposes I did not want them on a subdomain.
Rails configuration
Add to Gemfile:
gem "rack-reverse-proxy", :require => "rack/reverse_proxy"
Now we want /blog and /blog/ to be directed to the Wordpress instance from the Rails app.
Add this to your config.ru right before you run the app:
use Rack::ReverseProxy do
reverse_proxy(/^\/blog(\/.*)$/,
'http://CHANGEME.herokuapp.com$1',
opts = {:preserve_host => true})
end
In config/routes.rb add a route:
match "/blog" => redirect("/blog/"), via: :all
Original Ref: http://rywalker.com/setting-up-a-wordpress-blog-on-heroku-as-a-subdirectory-of-a-rails-app-also-hosted-on-heroku
这篇关于单个域上的多个Heroku应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!