Reputation: 12379
I have two domains on Apache: domain1.tld
& domain2.tld
Presently I have domain1.tld
working perfectly with Passenger, but I also need domain2.tld
to point to this same application, but when it reaches this second domain, it will have different functionality (ie, call a different controller and have some different routes) than when a user hits domain1.tld
.
How do you configure this traditionally in Rails?
As far as the Apache config goes, I have the following for 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
What would be needed for domain2.tld
for the Apache config?
Upvotes: 3
Views: 131
Reputation: 3326
Your setup at some point might also evolve into having two completely separate apps. And I'll let you be the better judge of when and when not that might be required. Having said that you can achieve what you asked using Routing Constraints in Rails. For ex: (Please note that this is not the only way of achieving this, but my preferred way)
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'
To add a new Apache host, one adds another virtual host and points to the same public folder as the main application. So in this case, it would be a matter of creating all of the same information as in the first config file, but just adding the domain2.tld
as the new virtual host's name.
Upvotes: 2