Virtual Hosting: Home: Difference between revisions
(New page: <span id="top"></span> <div style="padding:0;margin:0; border-bottom:3px inset #000000"> {| | MPG UniCenter || Virtual Hosting: [[Virtual Hosting: Home | Ho...) |
(No difference)
|
Revision as of 18:12, 21 June 2008
Virtual Hosting: Home | Name based | PAC | Browsers and PAC | Making it portable | Issues |
Virtual Hosting |
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 Apache will process any URL on this port regardless of its origin.
Clients
URLs consist of several pieces of information 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) adds other pieces to the original request for example referrer once assembled is sent to the server.
Of importance 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 you use Virtual Host sections in Apache’s configuration file for each domain name.
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 (you can restrict certain areas if you wish) accessible by Internet users. Root folder names are not visible from the Internet any folder above a root folder are not accessible while folders and files within and below the root are.
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.
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 a users why they have been redirected.
You are free to place root folders where you like however their location impacts on the paths you specify in each host block. The following explains this in a little more detail.
Configuration 1
Web sites 1 to 3 are large these will not fit on a USB stick hence have been located at the top level of drive I. These sites could have been placed on their own drives. They are not portable when Uniform Server is run 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.
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 saves creating an extra root folder. |
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 folder www this no longer functions as a root folder it is used purely as general-purpose folder. Doing this I have created a separate folder site_default which will be used as the default.
Non-portable If I want a fixed installation I would use absolute paths as follows:
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)
|
This configuration has one minor disadvantage it is not compatible with apanel’s Vhosts I have no problem with this because I manually edit files by choice.
Configuration 3
This configuration I use in the tutorial although not portable 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, 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.
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. Ho and that includes file names. |
Summary
The above gives you a feel for what’s going on its 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.
Ric |