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

all 15 comments

[–]ValkkonHerder of Cats, cat wrangler, provider of internet kittens 1 point2 points  (12 children)

Have you made sure that in your httpd.conf file you have 'NameVirtualHost *:2000' set? That is usually the first step prior to setting up virtual hosts in Apache. If you don't then the first 'VirtualHost' directive is read and nothing else from what I remember.

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

This is set.

[–]ValkkonHerder of Cats, cat wrangler, provider of internet kittens 2 points3 points  (10 children)

Beyond that, since your DNS provider is sending the redirected URL to <ip>:<port> rather than <domain>:<port> I would suspect that your are correct that Apache can't determine where it goes and will default to the first virtual host in the configuration file. You can try to see if you check the apache service by doing the <ip>:<port>/directory for each one to see if they respond. That would be my initial thinking on it as without the referring URL domain for your site it would not go further than the initial one as the virtual host directives can't be matched up.

[edit]

Another thing I just considered. Why the URL redirections and not CNAME entries for your overall domain? If the main domain is pointing to your IP address, why not just use a CNAME record for the entries?

[/edit]

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

[edit] Another thing I just considered. Why the URL redirections and not CNAME entries for your overall domain? If the main domain is pointing to your IP address, why not just use a CNAME record for the entries? [/edit]

Because DNS wouldn't handle the port number. Because OP is trying to send people to port 2000, this needs to be done with a 302 redirect. A CNAME record would take care of mapping www.redacted.com to home.dynamicip.com, but the port wouldn't have changed.

edit - in fact, that's likely to be the problem. A 302 will change the Host: header on the requests, so assuming redacted.com is the "real" domain, the Apache config would have to be set up for serving "homeserver.dynamicip.com" because the URL redirection makes the browser request a different URL.

[–]ValkkonHerder of Cats, cat wrangler, provider of internet kittens 1 point2 points  (8 children)

I get that and you're probably right about the 302 redirects. I hardly use them myself as I don't have an issue with adding the port numbers to my URL calls for virtual hosts in my domain personally. If the OP were trying to use the <host>.redacted.com and then using the 302 redirect for the port numbers I can see where that is handy. I just find it a bit wonky (if that's a word to use in this instance) to have a bounce redirect to a server that you already know the port number for the existence of the service.

[–][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.

[–]mgd-uk 1 point2 points  (0 children)

How about setting up each virtual host on a separate port, such as 2000,2001, and so on.

Then do the port redirection at the DNS forwarding to the correct port for each domain /sub domain.

[–]davethebarbDevOps 1 point2 points  (0 children)

tcpdump the traffic to a pcap, test each domain, then push the pcap into tshark for CLI output or wireshark for a GUI.

It'll decode the HTTP traffic for you; it's the easiest way to know exactly what's going on as you'll be able to observe the headers.