Two origin servers one dedicated for API - how to?

Hello, I cant seem to figure out how to do this with Cloudflare? I totally know how to do it in an nginx config on my own server, but I need to split these requests prior to ever hitting my server, seems like something Cloudflare should be able to do, but… I can’t figure it out.

(no redirects, just reverse proxy the two different servers, all api requests go to server a.a.a.a all web requests go to server b.b.b.b)

https://mydomain.com -----------[cloudflare]-----{mydomain.com/api?stuff}----a.a.a.a server
                                     |_______{mydomain.com/everything_else----b.b.b.b server

in nginx i would simply have two different location blocks one proxy_pass to a.a.a.a matching the url path /api* and a second location proxy_pass to b.b.b.b that catches everything else… but i want this split to happen on Cloudflare before the traffic ever gets to my nginx servers… Posted once before, sorry for the second post, no one responded to the first one and I couldn’t “bump” it :slight_smile:

You can do this in an Origin Rule.

am i missing something? I dont see where i can change dns or anything, i can only change port?

Because the rest of the settings are only available in Enterprise plan only.

1 Like

Killing me Cloudflare… I’m a little guy, Enterprise only… boo… Guess ill do it on my nginx server… double up all of those connections through Cloudflare. seems inefficient (for Cloudflare). :slight_smile:

I think I might suggest a Worker for this, as that will get you a lot of flexibility, and is much faster than nginx, simply by virtue of being on the edge and existing in an ephemeral space V8 engine.

In fact, re-reading for understanding… This is ideal for a Worker. You could use the routing template to send requests to specific origins quite easily with await fetch(a.a.a.a) and await fetch(b.b.b.b). It’s not truly a reverse proxy, but it does accomplish the same.

You could also authenticate preliminarily, or even entirely, in the Worker, if you’re feeling fancy.
…You might get addicted, though, and find yourself using KV and then Durable Objects…and maybe even D1 or R2 O.o

Thank you for thinking outside the box for me. I already looked into workers. they only support 100k requests per day on the free plan… my site sees 5.3Million in 24 hours… :slight_smile: