We help IT Professionals succeed at work.

DNS  for server on  specific port on an AWS EC2 instance

Hilbert Taylor NZIA
on
135 Views
Last Modified: 2020-06-02
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.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2007

Commented:
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.


David FavorFractional CTO
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
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).
Fractional CTO
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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 ?
CERTIFIED EXPERT
Top Expert 2007

Commented:
No, you can't use DNS like this.

Redirectuin is you option based on domain name.

Author

Commented:
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"?

Commented:
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.

David FavorFractional CTO
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
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.
David FavorFractional CTO
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
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.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.