Virtual Hosting

 
1 Overview
----

Apache Virtual Hosting replicates the majority of internet sites. This page demonstrates how to accomplish __Name Based__ virtual hosting. There are 4 steps

# Install / Configure Apache
# Create a Virtual Host
# Create a Document Root
# Set Permissions
\\

1 Details
----


1.1 Configuring Apache

This is nearly trivial as Apache is ready to go out of the box so to speak. If you've already installed it, the entire extent of changes are to uncomment a line in one file and use the sample vhost file as a template to create a new one from which you can do with a sed command. After you create the appropriate directory you are ready to restart apache and you're done.

- Open for editing the file ~~/etc/apache2/listen.conf~~
- and uncomment the line ~~NameVirtualHost *:80~~


1.1 Create a Virtual Host

Go to the ~~/etc/apache2/vhosts.d~~ folder. We are going to execute the following line against the ~~vhost.template~~ file

{quote}
cat vhost.template | sed s/dummy-host.example.com/www.your-site.ohio.edu/g >www.your-site.ohio.edu.conf
{quote}

You can then edit the top of the file with the contact email should you desire

1.1 Create the vhost's document root

This was set in the vhost.conf when we created it so now we need to create one to match that setting.

{quote}
md /srv/www/vhosts/www.your-host.ohio.edu/
{quote}


1.1 Own and Apply a Default ACL

{quote}chown -R upi01 www.upi.ohio.edu{quote}

This makes the folder owned by the account in question.

{quote}setfacl -R -d -m group:finance:rwx www.finance.ohiou.edu{quote}

This makes it such that all new files inherit the new permissions.


1.1 Log Rotation

Adding virtual hosts creates additional log names that the log rotate deamon may not be prepared to handle. Use the information in [Best Practices/Software/AWStats/Clients/Apache] to set up rotation rules for both;
- access_log
- error_log





\\

1 Additional Resources
----
1.1 Mixing VHosts and The Default htdocs folder

In short, you can't do it. Here's a snippet.

{quote}
As a consequence, the first listed virtual host is the default virtual host. The DocumentRoot from the main server will never be used when an IP address matches the NameVirtualHost directive. If you would like to have a special configuration for requests that do not match any particular virtual host, simply put that configuration in a <VirtualHost> container and list it first in the configuration file.
{quote}

See this entry as well [start/2006-04-07/1]

1.1 Extended ACLs

This is a rather large topic, but here is a starter link

http://www.novell.com/documentation/oes/sles_admin/data/sec-acls-handle.html#sec-acls-handle_defacl_eff



Notes:
Right now we are Name Based virtual hosting them on an apache server, and I learned something new while setting up a trial run. You'd think that if a a client made a request that didn't mactch any of the Named VirtualHosts it would be handled by the default server. Not so it turns out, "...the first listed virtual host is the default virtual host. The DocumentRoot from the main server will never be used when an IP address matches the NameVirtualHost directive."

So if you use __name based__ virtual hosting the IP address field will always match so your first vhost is the default.If you are using the vhosts.d folder and seperate files for your vhosts, it seems to be the first one alphabeticaly wise.
Comments