问题
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?
回答1:
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
回答2:
I’m probably late to the party, but it is possible. Short version of how we did it at Pilot:
We have an additional instance running HAProxy. It’s responsible for routing requests to corresponding Heroku apps based on their URL. ✌️
回答3:
Your best bet is to turn your Rails apps into Rails engines:
http://pivotallabs.com/migrating-from-a-single-rails-app-to-a-suite-of-rails-engines/
And then mount each engine with the URLs you describe.
Of course, this is probably going to be tricky if your apps are very large and complex.
来源:https://stackoverflow.com/questions/19119164/multiple-heroku-apps-on-a-single-domain