Apache Virtual Host Configuration
Notes on how I usually do it, on Fedora.
- The interesting directory is /etc/httpd/conf.d
- One virtual host (and its aliases), per file
- Files get processed in alpha order
- use #-sign for comments
in the default httpd.conf (/etc/httpd/conf/httpd.conf)
# note: usually this is just turned off (commented out)...
# Use name-based virtual hosting.
#
#NameVirtualHost *:80
NameVirtualHost *:80
"default" host (zzvh.aaa.conf)
# remember that ServerName/ServerAlias must be resolvable (DNS or hosts)
<VirtualHost *:80>
ServerName example.com
ServerAdmin nobody@localhost
DocumentRoot /var/www/html
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
</VirtualHost>
all other hosts (zzvh.someserver.conf)
# this is the "normal", useful part
<VirtualHost *:80>
ServerName someserver.example.com
ServerAdmin root@someserver.example.com
DocumentRoot /home/someserver/www
ScriptAlias /cgi-bin/ /home/someserver/cgi-bin/
</VirtualHost>
# this bit makes the homepage of www.blah.com equal blah.com
<VirtualHost *:80>
ServerName www.someserver.example.com
Redirect permanent / http://someserver.example.com
</VirtualHost>
# this bit makes blah.net and www.blah.net equal blah.com
# probably a cleaner way to do it, though
<VirtualHost *:80>
ServerName someserver.example.net
ServerAlias www.someserver.example.net
ServerAdmin root@someserver.example.com
DocumentRoot /home/someserver/www
ScriptAlias /cgi-bin/ /home/someserver/cgi-bin/
RedirectMatch /(.*) http://someserver.example.com/$1
</VirtualHost>
date: 08/16/2007, updates 06/20/2008
|