Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've been trying to figure this out for a while. I've been googling but I couldn't really figure it out.

I have bunch of VPS's for my clients. Each has its own IP address, with a single website on it, and its own domain name which the client controls (so I have no access to their DNS settings). I setup the hostnames of the VPS's as a subdomain of my website (srv01.companyname.com, srv02.companyname.com etc.) and have an A record for each one of them, pointing to the IP address assigned. I also have a reverse DNS that matches each IP address with its companyname.com subdomain (or hostname), as this seems to avoid outgoing emails being considered spam.

I tell clients to create CNAME records and make them point them to their VPS's hostname (ex. srv01.companyname.com). This setup is solid for me because since I don't have control over the domain names, if I had to move the VPS and/or change its IP address I could do it independently, by just changing the A and reverse DNS records, without any action from my client.

Now, the problem is that everything works, but while you can see the website on the main domain name, you can also see it on the companyname.com subdomain, which I don't really want.

So I have 2 questions: 1) is there any way to avoid this? Would there be another way to have domain names use CNAME records so that I could still have control over the IP addresses, without the website being visible on the subdomain?

2) if there is no way and I have to have clients point their domain name to the IP address directly, what should I set the hostname to, for reverse DNS to work? Could I still keep the same hostname and reverse DNS and emails would go through OK?

I appreciate any help or advice.

Thanks!!!

share|improve this question
add comment

1 Answer 1

I don't know what server you are using but you can tell vhosts in Apache and Nginx to ONLY listen to specific domains (transmitted in the host header. Therefore you could either:

  1. Add a vhost to your config that matches the srv$.example.com and let this redirect to your main page.

  2. Set the default vhost to a redirect and make a specific domain specific vhost to serve the client's page

share|improve this answer
    
Hi Christopher, thanks for your answer. It is Apache indeed. So if I add the vhost config on example.com (I assume it's /etc/hosts), this will only redirect when srv1.example.com is visited with a browser (ex. all other stuff such as DNS CNAMES, etc.) will keep working? Also, do you see anything unusual with my setup? using CNAME records won't let me support domain names with 'www' omitted, right? I really appreciate your help. –  jason Sep 26 '12 at 18:33
    
First the vhosts are configured in Apache. Read here for more info: httpd.apache.org/docs/2.2/mod/core.html#virtualhost. Second the www should always be a CNAME to the primary domain. The easiest way for this would be option 1. Then you wouldn't have to setup two vhosts. –  Christopher Perrin Sep 26 '12 at 19:38
    
Thanks, Christopher! I'll try see if I can figure it out :-) –  jason Sep 26 '12 at 20:11
    
I tried, but no luck. I think the problem is that my httpd.conf doesn't use vhosts... I use Apache's default config file, so the website is under <Directory "/var/www/html">... In the main domain, I should probably add a rule inside <Directory> that says 'if host starts with srv* redirect to companyname.com'... but have no idea how to do that. Any idea? Am I on the right track? Thanks!!! –  jason Sep 26 '12 at 21:09
    
You could mix it. Just add a vhost for the domain you DON'T want to serve and serve a redirect or an emtpy page or whatever from it. –  Christopher Perrin Sep 26 '12 at 22:15
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.