How to get Rails application working on two domains, Reverse Proxy -
i have 2 separate application running on www.a.com
, www.b.com
. second 1 rails-3 application. common login working between 2 sharing cookies, redirecting requests on www.a.com/b
www.b.com
. using apache reverse proxy achieve this:
proxypass /b/ http://www.b.com/
this works fine apart fact asset/javascript links getting formed assuming www.a.com
root. example:
<%= javascript_include_tag 'js/bootstrap-datepicker'%>
is resulting in link http://a.com/assets/js/bootstrap-datepicker.js
whereas want http://a.com/b/assets/js/bootstrap-datepicker.js
i solving doing:
config.action_controller.asset_host = "http://a.com/analytics"
this works fine though find solution bit hacky. real problem starts when put links other pages in application. in order put link page named page
, need put b/page
in href. works fine when accessing application using a.com. doesn't allow me access app using b.com link starts pointing www.b.com/b/page
doesn't exist.
how can whole thing working can access application using either a.com or b.com.
an alternate solution problem, use sub-domain , cname/alias instead of reverse proxy.
instead of reverse proxying a.com/b b.com. point new.a.com application running @ b.com using cname/alias in dns.
set cookie domain a.com instead of www.a.com, cookies shared across subdomains.
config/initializers/session_store.rb
youapplicationname::application.config.session_store :cookie_store, key: 'some_key', :domain => ".a.com"