One domain but two different servers

Hello,

I have one domain lets say: mydomain.com. I have a CNAME for it that points to my Heroku server lets say: api.heroku.com.

Now I have one more heroku server web.heroku.com.

I want my requests to go like this:

mydomain.com/api/*  -> api.heroku.com
mydomain.com/* -> web.heroku.com

But the url should be the same ie. mydomain.com for all cases. Ie not a redirect that change the url to web.heroku.com. Is this possible to do using Cloudflare?

Today I have a reverse proxy in my api.heroku.com but this causes all requests to go via api.heroku.com. I would like to have Cloudflare to do that selection instead resulting in no web requests to reach api.heroku.com so I can remove the reverse proxy at my side.

That’s certainly a non-standard configuration. A hostname points to an IP address, so everything below that should be on the same server.

However, if you want to dig into Workers to pull subdirectory data from a different server, you can try something like this:

Oh I see. But is it really that uncommon to have your web, backend, blog etc on different servers but you still want the same domain?

Ex
Mydomain.com
Mydomain.com/api
Mydomain.com/blog

Anyhow. Thanks for the tip with workers. Might work with my use case. I solved it in another way for now.

I started a new, third, heroku dyno where I deployed a HAProxy. In the proxy config I pointed all requests to /api* to my backend.heroku.com dyno and the rest to web.heroku.com.
Then I “moved” the domain to the proxy dyno and changed the dns target to the proxy dyno here on cloudflare so all traffic pass trough it and gets redirected properly. Seems like it plays along nicely. Just thought I could do that directly on cloudflare and skip the third dyno :slight_smile:

If you are on an Enterprise plan you use the Resolve Override page rule. You may need to use Host Header Override The limitation is that the public and origin paths must match. If you cannot work with this limitation, you will have to use a worker.

2 Likes

This topic was automatically closed after 31 days. New replies are no longer allowed.