domain name system – How to redirect multiple subdomains through gateway server to internal app server with single IP address on different ports for each subdomain?

I am having a problem with trying to redirect subdomain url to a Application server that have apps on different ports but a single IP address.

Basically, here are the steps:
Client outside the network types in subdomain,, The DNS server is redirecting the information to a Gateway server, so all subdomains go to single external IP address This is done and it works, it shows the Apache default page. The problem i am struggling is to redirect each subdomain from the Gateway server to the internal App server with single IP address that have 3 apps for each subdomain on different ports.

Locally this works perfectly as i am calling the apps for example:,,

However, I want to redirect each subdomain that the gateway server received to the appropriate port on the single IP address App server, as in ->, – > and ->

I have tried with bind9, with apache virtuahost but no luck. I think I can try with squid also, however if someone can point something to use with apache or something else on Linux Debian. Is this possible ? As shown on the picture bellow.
enter image description here