18

Possible Duplicate:
How to use DNS to redirect domain to specific port on my server

My web application is running on myserver.mydomain:10000 I would like to make it available on the intranet as mywebapp.mydomain.

Reading Forward port to another Ip/port, I have looked into rinetd, but I don't fully understand how I can achieve my goal:

  1. create a cname alias mywebapp --> myserver on the name server
  2. run rinetd on myserver, redirecting port 80 to 10000 ?!?

That would redirect all http traffic.

I seem to have a gap in my understanding. Can anyone help me ?

4
  • What O.S. are you running?
    – Massimo
    Nov 16, 2009 at 10:48
  • Ubuntu 9.04 and FreeBSD 7.2, 64bit versions.
    – ssc
    Nov 16, 2009 at 22:57
  • did you ever find a way to do this with rinetd?
    – fschwiet
    Jan 10, 2012 at 4:17
  • never tried rinetd as things worked fine using a reverse proxy on apache as shown in the answer below.
    – ssc
    Jan 16, 2012 at 2:46

3 Answers 3

24

If you don't want to create another IP, then all you can do is install a reverse http proxy on the main IP and a name based virtual host to route the traffic using mod_proxy.

Here is how you can do it with apache, almost any http server can do it, other popular alternatives are squid, nginx, lighthttpd, etc.

Listen IP_ADDR:80
NameVirtualHost IP_ADDR:80

<VirtualHost IP_ADDR:80>
  ServerName  yourname.yourdomain

  ProxyPass        / http://localhost:10000/
  ProxyPassReverse / http://localhost:10000/

</VirtualHost>
4
  • GREAT! That solves my problem, thank you very much! Tried it out right away, works like a charm. :-)
    – ssc
    Nov 16, 2009 at 23:04
  • 1
    I tried this get easier access to my web app, and at first it seemed to work, but then I got all kinds of weird errors - Chrome Dev Tools were telling me that CSS and JS files were sent out with the wrong MIIME types, it complained about a stray < in jquery.js, which definitively is not there, etc. Not sure why - no problem with mimetypes when I access the server directly, must be Apache being over-active. Jul 12, 2015 at 12:20
  • Hw do you achieve this using nginx?
    – user_mda
    Aug 24, 2016 at 18:45
  • Does this route all traffic through the Apache server?
    – joshlk
    Jan 22, 2018 at 17:12
7

DNS only maps hostnames to IP addresses, it knows nothing and can't do anything about ports.

A solution to your need could be using a NAT router/firewall to forward you'r public IP's port 80 to the internal server IP's port 10000.

5
  • Thanks for your reply! :-) There's no public IP involved, everything happens within the intranet, one single network, no routing whatsoever. Moreover, NAT would redirect all HTTP traffic, I only want to redirect mywebapp.mydomain:80 to myserver:mydomain:8080 and mywebapp does not exist as a logical host, but only as a cname (or so)
    – ssc
    Nov 16, 2009 at 9:20
  • 2
    You should consider using the reverse proxy functionality of your webserver. Nov 16, 2009 at 9:25
  • If you're in an intranet, IP space can't be at a premium, so just allocate more IPs.
    – womble
    Nov 16, 2009 at 9:37
  • You're right, I have as many IP addresses as I could possibly need. Would you care to elaborate how that helps me ?
    – ssc
    Nov 16, 2009 at 22:57
  • He probably means: DNS points a name to an IP so just run each service on a separate IP, and set up a separate DNS name for each IP/service. Then run your service on the port you want it on, rather than redirecting it.
    – pilavdzice
    Jul 20, 2015 at 18:53
0

I assume you're wanting just one site redirected as such, and you run other sites on port 80 already? If so, and you are not using HTTPS (SSL), then you can either set up Apache to handle this domain as mentioned, or you can teach Apache to do the forward itself, to port 10000.

I know know what server OS or http server you are using though... so can't help more.

Not the answer you're looking for? Browse other questions tagged .