Can I run a reverse proxy inside the BEAM and serve multiple domains from one phoenix deployment?

I have a phoenix app and I have multiple customers for it.

Each customer of mine would like to run my phoenix app under their own domain name and the versions of the app shown at the different domains should differ only in the color scheme.

So what I would like to do is figure out a way to intercept the incoming request, examine which domain the user is trying to reach, and then serve the same app but with different CSS applied according to the requested domain.

In other words, instead of running my app at a particular domain, I would like to run it on 1,000 domains – but I don’t want to deploy my app 1,000 times.

Is this something that it is possible to achieve?

1 Like

Yes, we do this at my company. Based on the host we set a theme, and then based on the theme we pick one of several CSS packages. This works reasonably well, although there is a fair bit of CSS builder boilerplate that is a pain. If each of your 1000 customers can customize their CSS then you’ll need to do some fancy CSS to parameterize things, but switching theme by host in phoenix is the easy bit for sure.

3 Likes

Similarily, we provide an API which you call via REST at https://<your-slug>.someapp.com and we use the subdomain to figure out the account ID.