Jump to content

Link subdomain to specific port

norim_13

Hi guys!

 

I bought a domain a few months ago, and no problems so far. I have it pointing to my home IP, and whatever I host is fine once I specify the port on the URL (e.g.: mydomain.com:2000 )

Although this is fine, it's not perfect... What I wanted to do is to create some subdomains, and make each one point to a specific port. E.g.: sub1.mydomain.com => mydomain.com:2000, sub2.mydomain.com => mydomain.com:3000 )

 

Is this possible? I googled it, and from what I read I think it should be possible by using SRV records, but I haven't had much luck with that...

 

The configuration I have under advanced DNS settings in the domain admin panel is:

jKfQhq6.png

 

Left side field is something like that but with my domain details, and the right side field follows the following format (in "my_ip" I have my home IP address):

40n2mIH.png

 

When I try to access the page through the browser, it's not found (404). But if I navigate there by the main domain and specifying the port, the page is shown (mydomain.com:port).

 

Is there something very evident that I'm doing wrong? Or is the problem not something "troubleshootable" only with this info?

 

Thanks in advance. And please apologize my English, Portuguese is my mother tongue :P

 

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Hmm... ok. Not what I wanted to hear...

 

And isn't there anyway for it to be done internally (in the server)? Like "redirecting" requests for a specific domain to different applications inside the machine?

Link to comment
Share on other sites

Link to post
Share on other sites

SRV ("SeRVice") records are for specific applications that support their ise - HTTP/S is not one of those applications. 

 

Redirecting the browser from port 80/443 to whatever port you need requires a web server listening on port 80 that is set up properly. (for apache) In the server config you would create a virtual site for each subdomain and either use HTTP response redirect headers (301-304, as appropriate) or a different source folder/file and use either PHP to make the HTTP redirect header, or use a javascript redirect.

Looking to buy GTX690, other multi-GPU cards, or single-slot graphics cards: 

 

Link to comment
Share on other sites

Link to post
Share on other sites

That actually makes a lot of sense, and I should have thought about that before. I was overthinking the whole thing :P

Thanks @brwainer

I'll try that tomorrow and let you know if I succeeded. I shouldn't have any issues anyway.

Link to comment
Share on other sites

Link to post
Share on other sites

Well, I spent a couple of hours trying this, but I don't think I'll be able to achieve what I want... I've tried PHP redirects and also .htaccess redirects, but both are only redirects, meaning that the link will change... What I wanted was for the link to remain the original (sub.domain.com/x/y/z), but to display the correct page (domain.com:15000/x/y/z). Is it possible?

Link to comment
Share on other sites

Link to post
Share on other sites

No.

 

If these services are all HTTP, then you could a load balancer with SNI to accomplish this, but otherwise you can't have a port open for a specific subdomain with only one IP address.

Link to comment
Share on other sites

Link to post
Share on other sites

with clever enough rules you should be able to do this in the apache main config via a VirtualHost - which AFAIK you can't do in a .htaccess file. Another route you can take is to have the HTTP server on port 80 use ProxyPass to proxy to the other servers in the LAN.

Looking to buy GTX690, other multi-GPU cards, or single-slot graphics cards: 

 

Link to comment
Share on other sites

Link to post
Share on other sites

I was trying to do the same thing a few months ago and it baffled me that it wasn't a common thing... I tried doing it with DNS, Apache, and even some trickery in a PFSense router and nothing would work... Then I finally found a way to do it with IIS.

 

What I did was make a new website with the hostname as subdomain.domain.com, then in that site do a reverse proxy in the URL rewrite rule pointing to the internal ip:port. IIRC, I had to add the URL Rewrite feature, it isn't in the default IIS install.

 

It works great for most things, but if that internal site redirects to a different IP or port in the local network it will fail... still looking into a solution for that. Basically what it does now is when that subdomain.domain.com is typed in it knows to load up whatever site you specified with that hostname, and all that site does is tell the browser what IP and port to look at.

 

Redirect.PNG.040427b6e5ae260ad38bd49dce4

Link to comment
Share on other sites

Link to post
Share on other sites

35 minutes ago, Scheer said:

I was trying to do the same thing a few months ago and it baffled me that it wasn't a common thing... I tried doing it with DNS, Apache, and even some trickery in a PFSense router and nothing would work... Then I finally found a way to do it with IIS.

 

What I did was make a new website with the hostname as subdomain.domain.com, then in that site do a reverse proxy in the URL rewrite rule pointing to the internal ip:port. IIRC, I had to add the URL Rewrite feature, it isn't in the default IIS install.

 

It works great for most things, but if that internal site redirects to a different IP or port in the local network it will fail... still looking into a solution for that. Basically what it does now is when that subdomain.domain.com is typed in it knows to load up whatever site you specified with that hostname, and all that site does is tell the browser what IP and port to look at.

 

Redirect.PNG.040427b6e5ae260ad38bd49dce4

ProxyPass is the Apache way of doing a Reverse Proxy, btw. That's why I recommended it as an option.

Looking to buy GTX690, other multi-GPU cards, or single-slot graphics cards: 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Tyvm @Scheer

It seems to be working perfectly! It would be nice to be able to redirect to other devices on the network (I'll be running this at my home server, and wanted to redirect some ports to my personal desktop), but this way it's great anyway. And a lot simpler than messing around with messy apache config files :P

 

If you ever find out a way to make this work for services hosted in other machines in the network, please let me know.

 

Thanks again!

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, norim_13 said:

Tyvm @Scheer

It seems to be working perfectly! It would be nice to be able to redirect to other devices on the network (I'll be running this at my home server, and wanted to redirect some ports to my personal desktop), but this way it's great anyway. And a lot simpler than messing around with messy apache config files :P

 

If you ever find out a way to make this work for services hosted in other machines in the network, please let me know.

 

Thanks again!

Why wouldn't that method work for other services on other machines on the network? Just put their IP and port in the rewrite rule. The only limitation is that this would only work with HTTP based services. But it's surprising how many things really are a variant of HTTP

Looking to buy GTX690, other multi-GPU cards, or single-slot graphics cards: 

 

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, norim_13 said:

Tyvm @Scheer

It seems to be working perfectly! It would be nice to be able to redirect to other devices on the network (I'll be running this at my home server, and wanted to redirect some ports to my personal desktop), but this way it's great anyway. And a lot simpler than messing around with messy apache config files :P

 

If you ever find out a way to make this work for services hosted in other machines in the network, please let me know.

 

Thanks again

 

I should clarify, it will work to redirect to other devices on the network, it will go to whatever IP:Port you put in the redirect URL spot.

 

The issue is that if subdomain.domain.com redirects to say 192.168.1.20:5000, and while you are on that page you click a link to 192.168.1.30:88 it will fail. You are fine doing subdomain1.domain.com to 192.168.1.20:5000, subdomain2.domain.com to 192.168.1.30:88, etc. I have about 10 redirects to 10 different machines, just keep making new sites.

Link to comment
Share on other sites

Link to post
Share on other sites

27 minutes ago, Scheer said:

 

I should clarify, it will work to redirect to other devices on the network, it will go to whatever IP:Port you put in the redirect URL spot.

 

The issue is that if subdomain.domain.com redirects to say 192.168.1.20:5000, and while you are on that page you click a link to 192.168.1.30:88 it will fail. You are fine doing subdomain1.domain.com to 192.168.1.20:5000, subdomain2.domain.com to 192.168.1.30:88, etc. I have about 10 redirects to 10 different machines, just keep making new sites.

Exactly, and to clarify one point, if you did want a link on the page of 192.168.1.20:5000 that took the user to 192.168.1.30:88, or whatever else, you would actually need to make the link point to the other subdomain, e.g. subdomain2, that proxies for that other host/port.

Looking to buy GTX690, other multi-GPU cards, or single-slot graphics cards: 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Yeah, you're right, I misunderstood what you were saying...

I'm having a problem now... Yesterday I successfully configured a site in IIS in my home server to redirect a subdomain to my personal desktop. After that, while installing owncloud in the server and creating a site to redirect another subdomain to owncloud, I probably messed up something, and now none works... All I get are 404s from IIS... Is there any obvious mistake I could have made that could lead to this?

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×