Subdomain forwarding

I am trying to route an address like http://[subdomain].[domain].com to http://[domain].com:[port]

I have already set up “a records” and all addresses I need to forward to are working.

I read that there are rules you can use that will perform this task, but I have set up redirects (both types), page rules, and origin rules but none seem to work.

I understand I should be using page rules but does anyone have any idea of an example I can use?

Any help would be appreciated. If you need pics let me know what to send.

Do you need to forward that way? Or do you really just need to achieve http://[subdomain].[domain].com to http://[server-ip]:[port]?

If yes, then set traffic for [subdomain].[domain].com to use the origin port in origin rules…

…and have [subdomain].[domain].com proxied and set to your origin IP address in the DNS. No redirecting is required.

If no, and you really need to redirect to http://[domain].com:[port] then you can use a page rule or redirect rule to do the redirect, but you will need to ensure the DNS record for [domain].com (@ in the dashboard) is not proxied (set to “DNS only”) if that port is not one that Cloudflare’s edge can accept connections on…

Thank you for the quick response!

Can you give a little bit more clarity on both of them as I am interested in learning both ways?

I do not completely understand “and have [subdomain].[domain].com proxied and set to your origin IP address in the DNS”. I believe this can’t be done because the ports I need are not supported by Cloudflare proxy so I am using “DNS only” for my A record currently pointed to my server IP, and all traffic is routed to the proper ports as expected.

I just can’t get the subdomain page rules to work properly for the second solution, it looks like they should but they do not, do you have an example? It seems like they are the most straightforward thing ever… Maybe I’m missing something that is a simple fix

You make the request without a port number, so you request http://subdomain.example.com which connects to Cloudflare on port 80. Cloudflare then connects to your server over port 8000 (as long as you have set the origin rule so requests where hostname equals subdomain.example.com are set to go to port 8000) effectively doing a port translation.

https://www.cloudflare.com/en-gb/learning/cdn/glossary/reverse-proxy/

I set up the origin rule for the hostname as specified but the hostname entered (with subdomain) does not resolve to the port number or any page at all.

I have tried proxies through Cloudflare and “DNS only” and neither of them work. Some of the ports I am trying to open are non standard ports as well. I am not sure if that matters with the Cloudflare proxy.

Is there possibly some way to test to see if my origin rule is actually translating to the correct address? The origin rule seems like it is doing nothing. If I can get it to do something it should work it seems.

What is the subdomain/domain name? Plus a screenshot of the origin rule would be useful.


I attached my A records as well as my origin rule, subdomain = Plex, domain is my website name, so it’s plex “dot” mydomainname “dot” com (sorry the post won’t go through with a link) forwarding to 32400 as the origin rule. See second post for image

The origin rule won’t do anything if the DNS records aren’t proxied. Set to “DNS only”, requests go direct to your origin server (so you’ll need to specify the port). Set to “Proxied” so no port is needed and the origin rule will connect Cloudflare to your origin on the custom port.

So I’ve heard that only certain ports work through Cloudflare proxy, I switched Plex to one of these ports and turned Cloudflare proxy on and still no luck. DNS does not resolve to a webpage, the origin rule doesn’t seem to be taking effect.

Have you got any other ideas? I can just use the ports to get to my sites but it’s kind of annoying for anyone else who wants to use my stuff. I greatly appreciate your help so far!

Set the DNS record to be proxied. Set the origin port on your server and set that origin port in origin rules.

If you put the domain/subdomain in here, I can then take a look…
https://cf.sjr.org.uk/tools/check

1 Like

https
://cf.sjr
.org.
uk/tools/check?5ea3cbd5b7cd468cbf2a40d9dcb6bed2

Sorry for the enter in there, it wont let me send links

It’s working fine. Just http://plex.example.com and I get a login page.

https redirects back to http, so that’s ok as per your first post (although if using a login, HTTPS should be used to be secure).

Site is proxied and the origin rule must be working to connect to your server port. Anything after that is down to your origin server.

curl -I http://plex.example.com
HTTP/1.1 401 Unauthorized
Date: Mon, 29 Jan 2024 18:55:24 GMT
Content-Type: text/html
Connection: keep-alive
X-Plex-Protocol: 1.0
X-Plex-Content-Original-Length: 193
X-Plex-Content-Compressed-Length: 157
Cache-Control: no-cache
CF-Cache-Status: DYNAMIC
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=g4cZA8CSp5SJXgQ2LdEZ7z1ZURVNqITDGcx%2BJXGdcD6krP1eufTAfdRqHNzZckoWoFTv4VuIn%2FMa4KK82nbdpTmhwcmoriMt87fSglYEtZX7uU0pym0x%2Fgdz7%2BfpfCy4ycIX6rUUatGW8Q%3D%3D"}],"group":"cf-nel","max_age":604800}
NEL: {"success_fraction":0,"report_to":"cf-nel","max_age":604800}
Server: cloudflare
CF-RAY: 84d3b0712c29dd70-LHR

Thank you sir/madam, you have saved me days and maybe weeks of heartache and pain.

That website is very helpful! I greatly appreciate it. Website links are working as expected.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.