0

I have a few different small websites, and for each one I have a hobby-level hosting plan that supplies way more bandwidth/storage than any of them individually need. Furthermore, every time I make a change to the stack I use, for example when I start using a newer version of a gem, I have to update each of them separately, and I have to run separate tests for each of them. There are also identical tables that each one has, for example Admin and Error.

So I've started to think about whether it would be possible to combine them into one single app, maybe with separate Controller folders that are treated as root by different domain names. Anyone have any experience hosting different websites from the same code base? Is this even possible?

Update: To add some more context, I want to host the whole thing on one server, possibly with one database, but with multiple controller folders that each represent a different website and a different domain. For example, I currently have smallapp.com and lilsite.com, and I'm paying for the same hosting plan for both (that is in excess for both their needs), and they both have an identical Error model, and I update both whenever I start using a new gem version. They're also using the same gems and libraries. Ideally, I would have an app called superapp, hosted with only one instance of the same hosting plan, sharing one SSL cert, that would have two controller folders called smallapp and lilsite. The route "www.smallapp.com" would somehow point to the /smallapp/home.html path, and vice versa. Users on both smallapp.com and lilsite.com could create errors in the same database, but they could never view files in the other's controller.

Joe Morano
  • 1,715
  • 10
  • 50
  • 114
  • 1
    If the models / controllers are more or less the same, you could have a look at `Apartment` gem to split your site into multiple separate sites. But as soon as there are some differences in the code, you are probably still better off to keep them as separate applications. It will become very cumbersome to manage individual changes.. you could consider to move parts of the application into microservices though, that each of your separate apps can leverage. For instance for managing comments, or logins. – bo-oz Jun 24 '19 at 05:03

2 Answers2

1

Without knowing the full context yes it's hard to provide the best solution, but its possible.

Yes @bo-oz is correct you could use Apartment gem for this. We currently use this where I work.

You could also just have 2 servers that deploy off the same repo/code base.

Specifically, you could have 2 Heroku servers that deploy off the same github repo. Then have 2 separate domains. When you deploy you will just deploy both servers off your master branch.

joeyk16
  • 1,357
  • 22
  • 49
0

It is possible.

  1. All the domains have to point to the same IP address which is the address of your server. For that you need to change the domains DNS settings.

  2. The web server (such as Nginx) has to direct all the requests (from all domains) to the same Rails application.

  3. In the Rails application the routes have to point to different controllers based on a domain. request.domain is available in the 'routes.rb' file. See this question for more information Rails routing to handle multiple domains on single application

Keep in mind that requests from different domains will not share the same session. That's possibly not what you want.

chumakoff
  • 6,807
  • 2
  • 23
  • 45
  • 1. is not necessary true : a same server can have multiple IPs assigned, and Nginx using them in multiple server blocks – colinux Jun 24 '19 at 12:43