How to expose my localhost subdomain?

My web application consists of the following:

  • Frontend listening to port 80
  • Backend listening to port 8080

Using Nginx, I was able to re-route traffic from my subdomain api.localhost to localhost port 8080.
When I send requests to api.localhost from localhost, the backend server is able to pick the requests up.
The problem is when I try to deploy my application to production, where I have cloudflare as my dns.
When I access, I can load my frontend pages.
When I access, there’s no response from the backend.
However, if I go to my vm and run curl on api.localhost, the backend is able to see the requests.
How do I reroute to api.localhost?

This sounds like something I’d do with a Cloudflare Tunnel: Configure an Ingress Rule to map to http://api.localhost:8080


Thanks! I’ll try adding an ingress rule as you mentioned.

Out of curiosity, is it possible to achieve this with only the dns settings?
I’d like to try setting this up without any cloudflare-only software if possible

DNS only doesn’t forward ports. It only replicates what you already have without using any part of Cloudflare (what you already had before adding your domain here).

The only exception is SRV records, which tends to be application-specific. Your application would need to support it, but that’s separate from any Cloudflare functionality.


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