Can't get origin rules to work

I have 2 A records, each for a subdomain pointing to the same IP:

[sub1].[mydomain] points to [myIP]
[sub2].[mydomain] points to [myIP]

I have 2 origin rules set to redirect each subdomain to specific ports, so that:

[sub1].[mydomain] redirects to port 26388
[sub2].[mydomain] redirects to port 26895

I am sure I have the rules properly set up, for example:

if http.host eq [sub1].[mydomain]
then
rewrite to port 26388

However, these rules don’t work. When I try to access the subdomains without specifying a port in the URL, I get a “Welcome to nginx!” page.
When I access the subdomains and specify the correct port, it works just fine.

I have tried both proxied and non-proxied A records, and have also tried setting up SRV records for each subdomain and port, but to no success either.

Have I missed something?

Thanks!

The A record needs to be proxied, or the request won’t pass through Cloudflare for the rule to be applied.

The sounds like an issue with your nginx configuration around the host name. If the request is reaching your origin, the Cloudflare origin rules are doing what they should.