< Day Day Up > |
Recipe 22.10. Hosting Multiple Domains with Apache22.10.1 ProblemYou want to host several different domains on a single Apache server, sharing a single IP address. You've already registered all your domain names and have DNS in place for each one. 22.10.2 SolutionUse Apache's VirtualHost directives to set up name-based virtual host support. Here is a sample httpd.conf entry for serving two different domains: NameVirtualHost *:80 <VirtualHost *:80> ServerName www.tuxcomputing.com ServerAlias tuxcomputing.com *.tuxcomputing.com DocumentRoot /var/www/tuxcomputing ServerAdmin admin@tuxcomputing.com </VirtualHost> <VirtualHost *:80> ServerName www.bratgrrl.com ServerAlias bratgrrl.com *.bratgrrl.com DocumentRoot /var/www/bratgrrl ServerAdmin admin@bratgrrl.com </VirtualHost> Each domain has its own separate root directory where the site files are stored. This allows you to easily set up subdomains, such as webmail.bratgrrl.com and wacko.games.tuxcomputing.com. However, this does not work by magic—you need to create DNS A records for each domain and subdomain. 22.10.3 DiscussionName-based virtual hosting is the easiest way to serve up multiple domains from a single Apache server. Configuring A records for a lot of subdomains can get a bit wearisome, but it's better than using a domain wildcard. A domain wildcard allows all traffic that includes your domain name to hit your servers. For example: Spammers will abuse a domain wildcard beyond belief, so you want to be careful to configure only your exact domain names in your DNS records. It is acceptable to use domain wildcards in your VirtualHost directives, because only domain names explicitly defined in DNS will ever see any traffic. Here is what each directive does:
Listen 80 Listen 192.168.1.5:8080 NameVirtualHost can use either of these. Remember that when you use a nonstandard port, such as 8080, users must specify the port in their URLs:
22.10.4 See Also |
< Day Day Up > |