apache customizations
2007-02-26 23:55:17 -0800
I wanted to set up a second site on a machine that was already hosting, so I looked into setting up VirtualHosts. Here are some bits that I learned that were not in the documentation or clear from the documentation. Everything outside of the VirtualHost containers are default settings for all containers. The first container is the default; if no container matches the requested host exactly, the first one will be used. So don't use a servername or serveralias in that container if you want a last resort default. You'll want to specify ServerName, ServerAlias, and DocumentRoot as minimum settings in your subsequent containers.
# Main configuration
# Example settings...
ServerName default.mydomain
ServerAdmin admin_address@mydomain
User www
Group www
DocumentRoot "/default/docroot"
<Directory "/default/docroot">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
IndexOptions FancyIndexing VersionSort
IndexOptions NameWidth=*
IndexOptions IconWidth=16
IndexOptions IconHeight=16
IndexOptions SuppressDescription
# ... other index settings
# ... many other settings
# Use name-based virtual hosting.
NameVirtualHost *
# Default host
<VirtualHost *>
# no ServerName directive
ErrorLog "logs/default-host-error.log"
CustomLog "logs/default-host-access.log" common
# These lines let us use the rewrite rules defined in the main configuration.
RewriteEngine on
RewriteOptions inherit
</VirtualHost>
<VirtualHost *>
ServerName virtualhost1.mydomain
ErrorLog "logs/vh1-host-error.log"
CustomLog "logs/vh1-host-access.log" common
DocumentRoot "/some/other/docroot"
<Directory "/some/other/docroot">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
# to enable serving up default "~/Sites" directories on Mac OS X
UserDir "Sites"
</VirtualHost>