We want to deploy a React app that can be accessed in the root path (example.com/) and a Rails app that can be accessed in a subdomain (example.com/backend). How can we do this in aptible?
Hi Maximiliano,
I’ll make two thoughts first, which aren’t exactly the answer you’re looking for, but highlight a few concerns and recommendations I’d have if I was in your situation.
Hosting on an Domain Apex:
Hosting on the apex of a domain (such as example.com instead of www.example.com) can introduce complexity for DNS/hosting. While this is possible on the Aptible platform, it requires some special attention, and if I was in your situation, I’d lean more towards hosting in the following manner:
- host a redirect at example.com to app.example.com
- host the frontend at app.example.com
- host the api at api.example.com
For instructions on hosting at the apex domain on Aptible, see: Using Domain Apex with Endpoints
Assuming that you move forward with hosting the apex domain on Aptible, you’ll then need to consider hosting your own nginx reverse proxy to handle the routing of traffic as you highlight in your example. Starting points:
- the official nginx docker image: Docker
- a note on using ngnix with Aptible endpoints as upstream targets: Using Nginx with Aptible Endpoints
In short, your solution would involve:
- hosting an nginx reverse proxy layer with endpoints having the apex record for example.com as mentioned above, routing example.com/backend to the api layer, and example.com to the react app
- hosting the react app on an endpoint used as an upstream by the nginx reverse proxy layer
- hosting the api on an endpoint used as an upstream by the ngixn reverse proxy layer
In my opinion, the above solutions involves a bit more complexity and cost (for the additional nginx layer), and I would steer away from it personally. However, it can be done, along the lines mentioned above.