If you can see this check that

next section prev section up prev page next page

Essential Apache


HTTP Server

User:
Password:

This tutorial is concerned with the configuration of an http server, namely Apache.

Question 1: Run the apache server

Each time you make a configuration change to the Apache server you must restart (or at the very least reload) the http service.

Get the server running.

Tests - not attempted
Run apache UNTESTED

Question 2: Add user directories

Apache allows you do have a URL which starts with /~username. This redirects the server to look for files in /home/username/public_html/. So for instance http://machine/~dave/hello.html would look for a file in /home/dave/public_html/hello.html.

To get this feature enabled, look through the /etc/httpd/conf/httpd.conf file for a line:

  UserDir disable

When you find this line delete it, or put a # infront of it.

Now create a user called "dave", create a public_html directory in dave's home directory, and create a file hello.html in the public_html. The contents of this file should be:

<html>
<body>
<h1>HOST</h1>
<p>
I am clever
</p>
</body>
</html>

The /home/dave, /home/dave/public_html, and /home/dave/public_html/hello.html file must be readable (and for the directories readable and executable) by other.

Tests - not attempted
UserDir seems to be disabled UNTESTED
Dave exists UNTESTED
Dave has a public_html which he owns UNTESTED
Dave has a home directory readable and executable by others UNTESTED
Dave has a public_html readable and executable by others UNTESTED
Dave has a file hello.html which he owns UNTESTED
hello.html is readable by others UNTESTED
hello.html contains the word HOST (case sensitive) UNTESTED
http://host/~dave/hello.html actually works UNTESTED

Question 3: Add two new directories/files

Create the following directories, each of which must be world readable and executable:

  • /home/dave/public_html/web
  • /home/dave/public_html/vm

In each of these new directories create a file similar to hello.html, except in "web/hello.html" replace the word HOST with WEB. In "vm/hello.html" replace the word HOST with VM. Case is important.

Tests - not attempted
Can read http://../~dave/web/hello.html UNTESTED
http://../~dave/web/hello.html contains WEB UNTESTED
Can read http://../~dave/vm/hello.html UNTESTED
http://../~dave/web/hello.html contains VM UNTESTED

Question 4: Create 2 virtual hosts

Using the <VirtualHost> tag in the httpd.conf file (add them at the end of the file) create two VirtualHosts.

The names of your virtual hosts have to be worked out by yourself from your current hostname. Type in the command "hostname" and you will get something like:

host-3-2.linuxzoo.net

Your machine is known by this name in DNS. It is also known by two other names, where the word "host" has been replaced with "web" and "vm". In this example of host-3-2, this machine is also known as:

web-3-2.linuxzoo.net
vm-3-2.linuxzoo.net

IMPORTANT: Do not just copy this example, as your machine number is likely to be entirely different. Use "hostname" and work your machine names out for yourself.

Once you have your web and vm machine names, create a virtual host entry for each of web-?-?.linuxzoo.net and vm-?-?.linuxzoo.net, so that the DocumentRoot of web is /home/dave/public_html/web and the DocumentRoot of vm is /home/dave/public_html/vm.

To use VirtualHost, the line

NameVirtualHost *:80
must be uncommented. In addition, each VirtualHost tagged area looks something like:
<VirtualHost *:80>
    ServerAdmin me@grussell.org
    DocumentRoot /home/gordon/public_html/db/public_html/activesql
    ServerName sql.grussell.org
    ErrorLog logs/sql-error_log
    CustomLog logs/sql-access_log common
</VirtualHost>

Tests - not attempted
Uncommented NameVirtualHost UNTESTED
VirtualHost detected for web-?-?.linuxzoo.net UNTESTED
VirtualHost detected for vm-?-?.linuxzoo.net UNTESTED
http://web-?-?.linuxzoo/hello.html contains WEB UNTESTED
http://vm-?-?.linuxzoo/hello.html contains VM UNTESTED

Question 5: Rewrite Rules

Add to the VirtualHost tag area for the "vm-?-?.linuxzoo.net" virtual host a ServerAlias for "host-?-?.linuxzoo.net". Remember to replace the ? characters with the details for YOUR machine. Once again, you can remind yourself of what this is by running the hostname command. After doing this the use of host-?-? should use the virtual host information for vm-?-?.

Add to the end of the VirtualHost tag area for vm-?-? a rewrite rule, such that any use of host-?-?.linuxzoo.net gets an external redirection to rewrite it to vm-?-?.linuxzoo.net.

Tests - not attempted
Server Alias detected for host-?-? UNTESTED
Redirect from host-?-? to vm-?-? is working? UNTESTED
No redirect from vm-?-? to vm-?-? UNTESTED

Question 6: Extended Rewrite Conditions

Adapt the rewrite rules for the previous question so that host-?-?.linuxzoo.net always gets rewritten using an external redirect to vm-?-?.linuxzoo.net unless the URI starts with a /~dave. Thus:

http://host-?-?.linuxzoo.net/hello.html   -> rewritten to -->  http://vm-?-?.linuxzoo.net/hello.html 
http://host-?-?.linuxzoo.net/~dave/hello.html   -> not rewritten and handled normally
Tests - not attempted
Redirect from host-?-? to vm-?-? is still working? UNTESTED
No redirect with host-?-?/~dave... UNTESTED
No redirect from vm-?-? to vm-?-? UNTESTED


Tutlinks: intro1 intro2 wildcard permission pipe vi essential admin net fwall DNS diag Apache1 Apache2 MySQL1 MySQL2
Useful: Quiz Forums
Site Links:XMLZoo ActiveSQL ProgZoo SQLZoo