| For this example, we'll be making use of name-based virtual hosts. Again, the
Apache documentation explains
this term very well. We will also be making use of their example. In this
example, I've registered two names both of which translate to my FreeBSD box. For
more information on how I actually did this, see httpd/dns.
The two host names in question are:
The server machine has one IP address, 192.168.0.45 which resolves to the name
test.freebsddiary.org. Here is what I've ensured is in my configuration file (/usr/local/etc/apache/httpd.conf):
NOTE: See the notes after this example.
...
Port 80
ServerName test.freebsddiary.org
NameVirtualHost 192.168.0.45
<VirtualHost 192.168.0.45>
DocumentRoot /usr/local/www/data/freebsddiary
ServerName test.freebsddiary.org
ErrorLog /var/log/freebsddiary-error.log
TransferLog /var/log/freebsddiary-access.log
</VirtualHost>
<VirtualHost 192.168.0.45>
DocumentRoot /usr/local/www/data/freebsddiary.yi.org
ServerName freebsddiary.yi.org
ErrorLog /var/log/freebsddiary.yi.org-error.log
TransferLog /var/log/freebsddiary.yi.org-access.log
</VirtualHost>
DocumentRoot is the location of the html files for the given virtual
website.
Newer versions of Apache can use combined logs. Search for CustomLog
in your Apache configuration file in order to see if you can use this format instaed.
In which case, these entries will be helpful as an example:
ErrorLog /var/log/freebsddiary-error.log
CustomLog /var/log/freebsddiary-access.log combined
The log and error files will be recorded in the directory /var/log/.
But you can put them anywhere you want.
If you specify an IP address for VirtualHost and supply the ServerName,
then you can avoid failures should DNS be unavailable when the configuration file is
parsed. For more detail, please see Issues Regarding DNS and Apache at
the Apache website.
This also assumes that you have pointed freebsddiary.yi.org and test.freebsddiary.org
to the same IP. In this case, 192.168.0.45.
So far so good. However, I've been unable to publish to my Apache Fp webserver.
I think that's because I've not told Apache which users can publish.
For details on how I did that, see Apache - who can
publish what?.
NOTE: I found that specifying NameVirtualHost as shown above, caused a
problem with the version of Apache I was using. So I removed it and virtual hosts
still worked.
NOTE: Although I am adding an IP address below, there is an easier way.
Thanks to James A. Peltier for pointing this out.
You should also see Apache - virtual hosts (continued).
|