Multi tenant with custom domain on rails

I am creating an application for several tenants, such as shopify, and want to know how to create my own domain on a server that points to the same instance of the application? For instance:

app1.mysystem.com == www.mystore.com app2.mystem.com == www.killerstore.com 

Do I need to do this configuration on CNAME, for example Google Apps? If so, how can I do this? Is there a good article showing how this works?

PS: app1 AND app2 points to the same application! Thanks

+3
source share
2 answers

I have a similar setup and I am using nginX. What I did for ease of maintenance, all connections from nginx were accepted and made filtering in my application.

 # application_controller.rb before_filter :current_client private def current_client # I am using MongoDB with Mongoid, so change the syntax of query accordingly @current_client ||= Client.where(:host => request.host).first render('/public/404.html', :status => :not_found, :layout => false) unless @current_client end 

You can have domain records with a domain / subdomain pointing to you_ip or your_domain_pointing_to_your_ip.com and record this in the form and save it in the database. Then change the request to current_client as follows:

 @current_client ||= Client.or(:host => request.host).or(:alias => request.host).first 
+6
source

I'm currently working on something similar, and just made a Nginx configuration. That is exactly what I did.

 server { listen 80; server_name domain1.com domain2.com domain3.com; rails_env production; passenger_enabled on; root /var/www/your_site_folder/current/public; } 

Also, make sure you use user_pre_start if you are using a passenger.

ex: passenger_pre_start http://your_domain.com ;

Add one line for each domain that you have added to the above configuration block.

The key here is under the name server_name. Normally I would use this for a domain using www.domain.com or without "www", domain.com. But in this case, you can specify all the domains from which you want to get into your application, and you have the Nginx setting for multi-tenant rent.

0
source

Source: https://habr.com/ru/post/952138/


All Articles