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 have a site that has many subdomains (one for each client). The content for each subdomain will be different, pulling different data, different layouts etc, so I don't think I can just alias one directory to many different sub domains. My question is, what's the best practice for doing this? Each subdomain will need SSL. My setup is

  • Amazon EC2 (ubuntu)
  • Wildcard SSL for my domain (*.mydomain.com)
  • Apache 2
  • PHP (LAMP)

Currently, I'm just creating a new entry into "/etc/hosts" and an appropriate spot in the web root (ie /var/www/abc.mydomain.com, /var/www/def.mydomain.com, etc). I've just discovered that I'll need a unique IP for each subdomain, and that's tricky with EC2 as they limit you to the number you can have (unless you jump through some hoops). Right now I have about 10 subdomains, which is manageable, but theoretically I could have thousands.

Am I doing it the only way possible or is there a better way I should investigate?

share|improve this question
2  
If you have a single wildcard certificate that works for all your domains, then you shouldn't really need multiple IP addresses. Normally you only really need on IP per certificate. –  Zoredache Apr 16 '10 at 20:55
    
I've learned a lot since this--and yes, the best solution was to get a wildcard DNS certificate that covers all subdomains with just one IP address. –  jnunn Sep 29 '12 at 18:14
add comment

1 Answer

up vote 4 down vote accepted

Is there a particular reason you are adding them to /etc/hosts? If the hostname resolves, that should be plenty for a more general purpose.

I like the directory structure you are using and that is very similar to any approach I would use. Additionally, I recommend specifying separate ErrorLog and CustomLog files for each subdomain.

Zoredache makes a fantastic point on IPs, as that your wildcard certificate should eliminate the need for multiple IPs when adding subdomains. Additionally, there is a newer Server Name Indication (SNI) feature that eliminates the need for an IP per each separate SSL certificate.

If you have thousands, that is typically where you might consider writing a script for managing the adding or removing VirtualHosts, sharing content, redirects, and other potential solutions. Options are going to be based on your exact needs at that time.

If you are talking about multiple user systems, the approaches are fundamentally different as well. For example, each domain would be in /home/user/public_html or /home/user/www.

share|improve this answer
    
Thanks for the tip on SNI. I wasn't aware of that option. –  Martijn Heemels Apr 17 '10 at 1:12
    
Thanks Warner, I just assumed I had to set each up in /etc/hosts. I don't have to? I'll investigate that and SNI. Thanks very much for your input and suggestions. –  jnunn Apr 17 '10 at 6:38
    
No. Typically /etc/hosts would be used for mapping fake hostnames for local use or changing how something would otherwise resolve locally. The primary server hostname would live in /etc/hosts but as far as every VirtualHost, I wouldn't. You're welcome. –  Warner Apr 17 '10 at 17:29
add comment

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.