1

I have a VPS which has 1 IP. If I run two socket servers, one on port 8080 and the other on port 8081, is there a way I can map service1.mydomain.com to the socket server on port 8080 and service2.mydomain.com to the socket server on port 8081?

I am NOT running a webserver, rather a websocket server on port 8080 and a socket server on 8081.

I have seen this question asked before, but it always seems to be about Apache, where I could edit the VirtialHosts file. As I am not using Apache, I can't do this.

Is it possible to do this? Or am I going to have to keep using mydomain.com:8080 and mydomain.com:8081?

The server is running Debian 8.

Thanks

user2370460
  • 213
  • 1
  • 3
  • 7
  • How is it "obvious" you aren't using Apache? What service is this and what are you using? You can't put port information in DNS unless the service supports looking for ports in DNS, but maybe you can get a proxy... – TessellatingHeckler May 31 '15 at 21:22
  • @TessellatingHeckler I meant that as I am not using apache, I obviously can't edit the VirtualHosts file. The services I am using are a python socket server, and a python websocket server. – user2370460 May 31 '15 at 21:25

2 Answers2

7

You cannot directly use a DNS name to map a specific port, in this case where you have a single IP for multiple DNS names.

Your best bet would be to setup Apache or NGinx as a Reverse Proxy to map service port based on "host header" (or Server Name).

Here is a sample for Apache :

<VirtualHost *:80>
        ServerName service1.mydomain.com
        ProxyPreserveHost On
        ProxyPass / http://service1.mydomain.com:8080/
        ProxyPassReverse / http://service1.mydomain.com:8080/
</VirtualHost>

<VirtualHost *:80>
        ServerName service2.mydomain.com
        ProxyPreserveHost On
        ProxyPass / http://service2.mydomain.com:8081/
        ProxyPassReverse / http://service2.mydomain.com:8081/
</VirtualHost>

So, you will need to setup a Reverse Proxy in front of your Websocket servers.


You will get :

  • http://service1.mydomain.com map and serve http://service1.mydomain.com:8080

and

  • http://service2.mydomain.com map and serve http://service2.mydomain.com:8081

Transparent for end-user.

krisFR
  • 13,280
  • 4
  • 36
  • 42
  • So just to check I understand, on the VPS I would install Apache, and have the above as the VirtualHost file. I add A records for service1.mydomain.com and service2.mydomain.com to the VPS IP, and then run my services on port 8080 and 8081? – user2370460 Jun 01 '15 at 19:23
  • 1
    Yes, you understand correctly :) With Apache running on standard http port – krisFR Jun 01 '15 at 19:24
1

You cannot map services to ports using DNS. If you open up 8080 and 8081 to the Internet, either domain can be used to access either port. However, if you are publishing URLs including the port number traffic will be routed appropriately.

If I assume these are web services, the normal approach would be to place a proxy (which could be Apache) in front of the services. Users would request service1.example.com or service2.example.com and the proxy would connect to the appropriate service. (I am using example.com as that is one of the domains assigned for examples.)

BillThor
  • 27,737
  • 3
  • 37
  • 69
  • Sorry, the services are a websocket server and a socket server. I should have been more clear in the question. – user2370460 May 31 '15 at 21:26
  • @user2370460 In that case, controlling published ports would be appropriate. I would use a port other than 8080, as that will receive a lot of HTTP probes. 8080 is a common alternative or internal port for web services. – BillThor May 31 '15 at 21:39
  • could you explain how I could do this? – user2370460 May 31 '15 at 21:58
  • @user2370460 this? Not clear what you are asking. I assume you have control of the services. They should provide information on how to configure IP addresses and ports. – BillThor May 31 '15 at 22:01