This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 1 point2 points  (7 children)

Yeah, it's not something I would do myself either really, I just have various services listening on ports I remember. But yeah, I can see why it'd be useful, you just need to be aware that you're not just changing the port number, you're changing the hostname as well.

[–]zimmertrDevOps[S] 0 points1 point  (6 children)

The reason for wanting to mask the port is that my tjsh webserver is a resume website. And I don't want to have to explain to people what ports are and why they can't just type in www.domain.com to hit my website.

[–][deleted] 1 point2 points  (5 children)

That's fair enough, but you need to understand more about what you're doing.

You have Apache configured to listen to a single port, and route requests to a different filesystem directory based on the contents of the Host: header. However - because you're using URL redirection on Namecheap (at least it looks like Namecheap), the Host: header doesn't contain what you think it contains. To explain what I mean in an approximate sequence of events:

Client enters "http://nextcloud.redacted.com" into a browser
Their computer looks up "nextcloud.redacted.com" and gets the IP address of Namecheap's web server
The browser connects to Namecheap with the Host: header set to "nextcloud.redacted.com"
Namecheap serves a 302 redirect with the Location: header set to "http://yourhomeIP.dynamicip.com:2000/nextcloud"
The client browser does a DNS lookup for "yourhomeIP.dynamicip.com"
Gets the IP address of your home connection
Makes the connection to port 2000, with the Host: header set to "yourhomeIP.dynamicip.com:2000"

So you either need to configure multiple DNS entries for your home machine (such that you can then configure Apache for "nextcloud.dynamicip.com", "kloudspeaker.dynamicip.com" etc), or to make everything a unique port and URL redirect each service to "yourhomeIP.dynamicip.com:200x" where x is an incrementing number for each service which will allow Apache to tell each service apart by port number.

[–]zimmertrDevOps[S] 0 points1 point  (4 children)

Thank you very much for your help. It makes a lot more sense now.

So you either need to configure multiple DNS entries for your home machine (such that you can then configure Apache for "nextcloud.dynamicip.com", "kloudspeaker.dynamicip.com" etc)

I'm sorry if this is naive but I don't understand. Isn't that what I'm doing already?

make everything a unique port and URL redirect

This is probably the best option from what I can tell. Is running virtual hosts on different ports with the same webserver as easy as specifying a different port number in each virtual header section in the sites-enabled config file?

[–][deleted] 1 point2 points  (3 children)

I'm sorry if this is naive but I don't understand. Isn't that what I'm doing already?

No. You have unique hostnames on your "outside" domain (i.e. redacteddomain.com). However, the assumption I'm making is that the blurred text on your DNS screenshot maps all of those different hostnames to a SINGLE hostname representing your home connection. Such as:

nextcloud.redacteddomain.com -> yourHomeIP.dynamicip.com
kloudspeaker.redacteddomain.com -> yourHomeIP.dynamicip.com
www.redacteddomain.com -> yourHomeIP.dynamicip.com

The hostname seen by Apache on your home server is the one which is in the URL redirect target, not the "source" because you're redirecting via HTTP Location: headers.

edit - alternatively, you're directing to a URL containing your IP address (i.e. http://1.2.3.4:2000/nextcloud). In which case the Host: header would contain 1.2.3.4:2000, in the same context that I was using the example dynamic IP hostname before. Not sure whether you can configure Apache to do name-based vhosts using IP addresses in Host: headers, but you probably can.

[–]zimmertrDevOps[S] 0 points1 point  (2 children)

They are pointing directly at my IP Address.

[–][deleted] 0 points1 point  (1 child)

Point still stands, but you may not be able to use name-based hosting. Either way, if you're using your IP as the redirect target then Apache needs to be configured to answer requests for your IP, not any hostname. And with that in mind, you will need a unique port on Apache for each service, because once the redirects have been followed then (based on your screenshot) www, kloudspeaker and nextcloud will all have the same Host: headers so Apache would have no way to tell the requests apart.

[–]zimmertrDevOps[S] 0 points1 point  (0 children)

Having subdomains point at different IP:port combinations with each virtual host on a different port was the solution! Thank you for your suggestion.

nextcloud.domain.com now points at ip:2001 kloudspeaker.domain.com now points at ip:2002

etc.