Usually people use proxy in the front, and direct the traffic based on
hostname. The proxy will listen on port 80 and 443 with valid
certificate, and your backend is listened on other non root port (e.g.
9001 for api1 and 9002 for api2).
Upon receiving the incoming connection proxy will check the hostname,
if hostname is `
api1.example.com`, proxy will forward the traffic to
backend at port 9001.
If hostname is `
api2.example.com`, proxy will forward the traffic to
backend at port 9002.
Your server
+----------+ +-------------+ (1) +-----------+
| internet | <===> | proxy | <====> | api1:9001 |
+----------+ +-------------+ +-----------+
^^
|| +-----------+
+========> | api2:9002 |
+-----------+
Some noticeable proxy application: haproxy.
--
Shulhan