Link to home
Start Free TrialLog in
Avatar of Hilbert Taylor NZIA
Hilbert Taylor NZIA

asked on

DNS for server on specific port on an AWS EC2 instance

Hello,

I am wondering if it is possible to setup domain name for service running of a specific port on an AWS EC2 instance.

I have an AWS EC2 instance I have defined a DNS for it : myec2server.com

on this instance I have two web application running on two different port : 8383 and 9898

I would like firstapp.myec2server.com to launch the application on port 8383 and  secondapp.myec2server.com to launch the application on port 9898.

Please Help.

Thank you.
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

DNS can't point to ports.

Protocols used like http or https run with well known ports.

For your case, you can have web server running on default port "(http -> port 80) and then redirect to the required port based on domain name used.


As omarfarid said...

DNS != TCP ports

To accomplish what you're trying to do, you can take several different approaches...

1) You can setup firstapp.myec2server.com + secondapp.myec2server.com each with their own IP, therefore there own port enumeration, so you can use any port you like.

2) You can setup HAProxy to proxy ports from on public IP to ports on a local IP or bridge adapter. This option will take a fair bit of time to setup + maintain. Also you'll have roughly a 50% speed drop (port proxy) or 25% speed drop (IP proxy for entire TCP protocol).
ASKER CERTIFIED SOLUTION
Avatar of David Favor
David Favor
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Hilbert Taylor NZIA
Hilbert Taylor NZIA

ASKER

The bottom line is to be able to use the same ip address and run application available on a specific port.

http://myec2server.com:8383  launches the application on port 8383 and  myec2server.com:9898  launches the application on port 9898.

Instead of that I would like setup these domain name  firstapp.myec2server.com and secondapp.myec2server.com
that will have the same result respectively.

if that is possible, how to set records  (A, CNAME, ALIAS, MX or AAAA) for that purpose ?
No, you can't use DNS like this.

Redirectuin is you option based on domain name.
Hey Omarfarid,
your first response was "For your case, you can have web server running on default port "(http -> port 80) and then redirect to the required port based on domain name used."
Could you please help with how to "redirect to the required port"?
What you want to do, has next to nothing to do with DNS

In this case, if I read your question correctly, you need a load balancer (as David pointed out).  

My suggestion - don't use different ports, have both app servers use the same port.  Put a load balancer in front of them. The DNS record will be something like: yourapp.ecserver.com.  This will point to your load balancer, which will then forward that traffic to your 2 (or more) servers.  You define in the load balancer how traffic is handled - round-robin, do you need session persistence, etc etc

You can set up a very basic load balancer, or you might need a more capable (also more complicated) one - depends on your needs and how the apps work.

1) You can't use DNS for this.

Another option will be to setup a custom Apache (or whatever Webserver you're using) config file to listen to many ports on one IP.

2) The way you "redirect ports" is by using a proxy tool like HAProxy (fastest) or NGINX (slowish + commonly used) or many others.

This type of tool is best used, only if you use this type of tool daily + you're a Debugging Savant, as setup/maintenance of this type of system is time consuming, normally requiring a good bit of complex debugging to get working, then keep working.
Suggestion: Open a 2nd question describing...

1) The code running on these 2x hosts, asking for design assistance.

2) The problem you're trying to solve by running multiple instances.

There may be other approaches, like load balancing or just tuning one instance to handle high through put loads.