Automatically host custom domains in Rails / Apache

I am currently developing a custom web application that gives each new user their own subdomain on the site, which is good (using subdomain_fu), but is there a way to allow the user to map their own domain to this subdomain?

I know how to do this manually using SSH login to the server and manually edit the Apache Vhosts file, but is there any way to do this automatically so that the user simply logs into their domain in the field on the site (obviously, they will have to change their DNS in another location)?

I am using Ruby 1.8 and Rails 2.3.3 on top of Apache.

Essentially

http://user.application.com/article-1 

can be accessed from

 http://userdomain.com/article-1 

Thanks for any help!

+4
source share
2 answers

Your users should be able to configure a CNAME record for their domain that points to your domain, for example

 userdomain.com. CNAME user.application.com. 

and then tell your application that they want to use userdomain.com as their host name. I do not think that you will have to change your vhost settings because your server will see a request for user.application.com , but check this by setting your own CNAME to be sure.

In your application, you will need to look at the host name, and if it contains application.com , you will do the same as now, but if it does not check you, is there a user who has set this domain as his own.

+1
source

I assume this is just one application that you want users to display different domain names, right? You do not need to use shared hosting at all, as all requests will be sent to the same Rails application, regardless of the domain name. If you use shared hosting, then the default virtual host (the one that handles http://1.2.3.4 if user.application.com resolves 1.2. 3.4) should be your Rails application.

0
source

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


All Articles