-2

I am running multiple web servers on a single machine.

localhost:9000

localhost:8080

I want external requests (from the open net) to mysite.com to route to port 9000 and myevenbettersite.com to port 8080.

I know the system hosts file does not accept ports so it cannot be used as a solution.

Would IpTables be the proper fit for this?

I would ultimately rather use something like the Mac Server or a Linux GUI to do this for more complex configurations.

This question is clearly about networking so is on-topic. What do you guys not like about the question?

1
  • I suggest this be moved to stackoverflow.com. Still a bit unclear why this info would be off-topic here since it is about networking
    – BAR
    Mar 25, 2015 at 0:08

1 Answer 1

3

No, you can't do this with DNS, IPtables or the hosts file.

You'd need to point those domains to a proxy, or something that has knowledge of what you want done, which will in turn re-direct the clients to the "right" place.

6
  • And what would this "something" be?
    – BAR
    Mar 23, 2015 at 15:21
  • 1
    Could be Apache, Nginx, HAProxy, or even just a simple script on the web server which can detect the Host header and return a Location header to redirect the clients.
    – GregL
    Mar 23, 2015 at 15:23
  • I know Apache can do this, but I am running a different webserver, and in this case multiple servers for each site (on a single machine), but it doesn't make much sense to run a webserver just to route to another webserver.
    – BAR
    Mar 23, 2015 at 15:25
  • I guess you'd have to pick one of the already installed web servers, have it be the default landing spot for all the sites, and then redirect to the right port/site. However, if you wanted to "hide" the actual ports from the users, then using a reverse proxy will do the trick because it can look at the host header and transparently redirect the requests to the "right" server.
    – GregL
    Mar 23, 2015 at 15:29
  • I think I can see the problems/solutions now. The webserver in question is the built-in default one the Play Framework uses. I will probably have to switch this to LightHttpd or Nginx to unify services and solve my problem.
    – BAR
    Mar 23, 2015 at 15:39

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