Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

What is Virtual Hosting?

Virtual hosting configures Apache to be able to host more than one website on the same computer. As an example, let's say this Apache Web Server will host both www.earth.com and www.krypton.com. Here is how the process works,

  1. Register domain names www.earth.com and  www.krypton.com
  2. Point to the server's ip address.
  3. User types in either url into their browser which would send a request to Apache.
  4. Apache reads the request header (which contains the url) where the user wanted to go.
  5. Based on the url, apache checks for a matching virtual host entry and directs the user to that virtual server's home directory.

In the future, I will put a diagram to illustrate.

Apache Differences on Ubuntu

Ubuntu/Debian organizes things slightly different than other systems when it comes to Apache. If you read other website that talk about Apache you might get confused. So here's how Ubuntu does things. You have the following key files,

/etc/apache2/apache2.conf - this is the default file provided during install and contains the default settings. If possible do not modify this file.
/etc/apache2/httpd.conf - location for global user configured options.
/etc/apache2/site-available/* - this is where you store your different virtual hosts.
/etc/apache2/sites-enabled/* - symbolic links here used to enable sites from site-available.

This is enough to get us started, but feel free to read more details at Control-Escape.

My Virtual Hosting Strategy

There are so many different ways of doing this it's quite mind boggling. Here's my overall strategy:

  • I want clients to come in and manage the pure html aspects of their website, so each website will have it's own group and clients will belong to the website's group.
  • Logging will be Virtual Host Based Logging. The pros and cons are are discussed in Apache Log Management.
  • Each virtual host will also have a,
    • browse-able "shared" folder to easily distribute files
    • "shared.private' where .htaccess is enabled so users can set their own authentication parameters and indexing
  • Most people only have one IP address to I'll use the "name based" hosting approach.

I find this approach is complex enough to address the needs of even complex banking applications and at the same simple enough to implement for the intermediate level user.

Create Virtual Host Files

Looking in /etc/apache2/apache2.conf you will see a reference to the directory, /etc/apache2/sites-enabled/. Apache will look in this directory and load any virtual host file configurations.

Assuming you are logged in as a member of the staff group, we will be creating groups and users with reserved ids as mentioned in the basic setup,

cd /home
sudo mkdir www.krypton.com # Home directory for the website.
sudo mkdir www.earth.com

cd /home/www.krypton.com
sudo mkdir www # Folder for static content
 
cd /home/www.earth.com
sudo mkdir www # Folder for static content

sudo addgroup \--gid 3100 wgkryptonian # Special work group to distinguish users who should have access to the website.
sudo addgroup \--gid 3101 wgearthling
 
cd /home

sudo chown \-R serveradmin:wgkryptonian ./www.krypton.com/
sudo chown \-R serveradmin:wgearthling ./www.earth.com/

sudo chmod \-R 775 www.krypton.com # Only svradm and users in the kryptonian group can manage. Apache(other's) still need to be able to read and browse.
sudo chmod \-R 775 www.earth.com

Now we create users that will have access to their respective websites,

sudo useradd \-d /home/kalel \-m \-u 2500 \-G wgkryptonian \-c "Client" \-s /bin/bash kalel # Add user kalel with additional group and make the user's home directory
sudo useradd \-d /home/jorel \-m \-u 2501 \-G wgkryptonian \-c "Client" \-s /bin/bash jorel
 
sudo passwd kalel
sudo passwd jorel
 
sudo useradd \-d /home/loislane \-u 2502 \-m \-G wgearthling \-c "Client" \-s /bin/bash loislane
sudo useradd \-d /home/jimmyolsen \-u 2503 \-m \-G wgearthling \-c "Client" \-s /bin/bash jimmyolsen

sudo passwd loislane
sudo passwd jimmyolsen

Next you create your physical virtual host file in /etc/apache2/sites-available and then create a symbolic link in /etc/apache2/sites-enabled/.

This article is still being transitioned from my old google wiki.

  • No labels