Virtual Hosting: Home

From The Uniform Server Wiki
Revision as of 00:07, 10 January 2010 by BobS (talk | contribs) (Ffix grammatical stuff and clarify)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

MPG UniCenter

Virtual Hosting: Home | Name based | PAC | Browsers and PAC | Making it portable | Issues

Virtual Hosting
Uniform Server 3.5-Apollo

Virtual hosting is extremely powerful. It allows you to host several domain names using a single Apache server. Before looking at Vhosts in detail the following background information may be of use. Certainly take a look at root folders.

Web Server

The sole task of a web server (Apache) is to translate a URL into a file name and send that file back over the Internet to a client (browser). URLs may translate to a program which Apache runs and sends the resulting output back. URLs are packages of information arriving on port 80 of the host machine. What’s important is that Apache will process any URL on this port regardless of its origin.

Top

Clients

URLs consist of several pieces of information. The basics are provided when a user types a web page address into a browser or clicks a page link. Once initiated a browser assembles all the pieces into a complete URL. It converts the domain name into an IP address (where the server can be found) adds a return IP address (allows information to be sent back to the client) and adds other pieces to the original request. For example, referrer, once assembled, is sent to the server.

It's important to note that different domain names can and do resolve to the same server IP address. A URL package of information allows Apache to separate out individual domains, giving the illusion of a dedicated server for that domain name. To achieve this operation, you create a Virtual Host section in Apache’s configuration file for each domain name.

Top

Root folders

A root folder is a folder you wish to make public to anyone on the Internet. Default for Uniform Server is folder www. All its content (sub-folders, files images etc) are potentially accessible by Internet users. You can restrict certain areas as needed using .htaccess files. Root folder names are not visible from the Internet. Any folder above a root folder is not accessible, while folders and files within and below the root are.

Top

Root folder location

Root folders are nothing special. They are the same as any other folder on your PC. There are no restrictions where a root folder is located. They can be on the same hard drive as the server or on separate hard drives. In general you would allocate one root folder per domain name. However if you wish, the same root folder may be accessed by different domain names. In this case you would be serving the same site content.

Note: If you are hosting several domain names and want to retain Uniform Server portability you must locate site root folders within or below folder udrive.

Top

Folder paths

The tutorial that follows shows how to host three sites. In reality you require an extra site referred to as the default. If for whatever reason Apache cannot resolve an incoming request it will automatically redirect to this default site, which contains a single page with a polite message informing users why they have been redirected.

You are free to place root folders where you like, however their location impacts the paths you specify in each host block. The following explains this in a little more detail.

Top


Configuration 1

Web sites 1 to 3 are large. These will not fit on a USB stick, so they have been located at the top level of drive I. These sites could also have been placed on their own drives.

They are not portable. When Uniform Server is run, they are not reflected in the virtual drive (w) created. See image on the right.

When you specify DocumentRoot the full path to a folder must be supplied.

  • I:/site1
  • I:/site2
  • I:/site3

Note 1: Moving Uniform server to a USB stick: When run on a different machine, Apache will fail to start. This is because Apache detects a configuration error (cannot find the root folders).

Note 2: In this example the extra site (default site) can be the main root folder www, which saves creating an extra root folder.

Top


Configuration 2

Where you place root folders tends to be a personal choice. This configuration reflects the way I implement my sites. I have assumed all three sites will fit on my USB stick. I have located these sites in folder www. This no longer functions as a root folder; it is used purely as general-purpose folder. I have created a separate folder, site_default, which will be used as the default.


I have two choices for folder paths:

Non-portable If I want a fixed installation I would use absolute paths as follows:

  • I:/us_test_server/Uniform Server/udrive/www/site1
  • I:/us_test_server/Uniform Server/udrive/www/site2
  • I:/us_test_server/Uniform Server/udrive/www/site3
  • I:/us_test_server/Uniform Server/udrive/www/site_default

Portable Apache runs on the virtual drive created. Because our site folders are reflected in this drive, it makes sense to use paths relative to this drive. More importantly there is no need to specify a drive letter. Use “/” to start from the top level. This gives the following paths (see image on the right):

  • /www/site1
  • /www/site2
  • /www/site3
  • /www/site_default

This configuration has one minor disadvantage. It is not compatible with apanel’s Vhosts. I have no problem with this because I manually edit the files by choice.

Top


Configuration 3

This is the configuration I use in the tutorial. Although not portable, it highlights several points. I have assumed site 1 is too large to fit on a USB stick hence is placed in the disk root (top level).

I have created a common folder z_www and placed the site root folders in this. The main root folder www becomes the default site, which has been automatically created. When using Vhost from apanel you will find this listed as default.

Path choice, site 1 dictates you use an absolute path, but for sites 2 and 3 you have two options: either absolute or relative to the virtual drive. It’s probably a good to make 2 and 3 portable hence use paths relative to the virtual drive.

  • I:/site1
  • /z_www/site2
  • /z_www/site3


Note 1: Regarding file paths, Apache is consistent between Unix and Windows. Always use a forward slash as shown.

Note 2: Root folder names (site1, site2 and site3) are not significant. Choose whatever you like, however make your life easy and NEVER use spaces; use an underscore instead. That includes file names, too.

Summary

The above gives you a feel for what’s going on. It's all about Apache finding the root folders so it can serve pages from them. On the next page I expand the ideas and show how easy it is to use apanel to set-up virtual hosts.


Top


Ric