CSc31800 Internet Programming

Spring 2004, CCNY-CUNY, Jinzhong Niu


Homework #1: Apache Web Server (due on Mon - March 8th)

If you want to do the homework on Solaris in UNIX-Lab, click here.

Note that this doc first explains how to obtain and run Apache before it tells what you should do as the homework. In your homework report, you should include what you have done for the last 3 parts, i.e. how to enable access control, how to configure Apache as a proxy, and how to set up name-based virtual hosts with Apache.

To download Apache

1. Download Apache1.3.38.zip, which works only on Windows.

2. Uncompress Apache1.3.38.zip to C:\temp\ and make sure you do so correctly by confirming you have the following tree structure:

 
C:\temp\
 |-Apache
      |- bin
      |- conf
      |- htdocs
      |- icons
      |- include
      |- lib
      |- libexec
      |-...
      .
      .
      .
To start/stop Apache

1. Open a DOS console.

2. In the console, enter C:\temp\Apache\, which we will call APACHE_ROOT later on.

3. Run apache. If anything goes normally, you will have the following in your console:

 
C:\temp\Apache> apache <Enter>
Apache/1.3.28 (Win32) running...
4. Run IE to visit http://localhost/ and you are supposed to see the homepage of Apache.

5. To stop the running Apache server, open another DOS console, and in APACHE_ROOT, run apache -k stop.
    Actually when you execute apache -h in APACHE_ROOT, you will see the usage information of Apache as follows:

 
C:\Temp\Apache>apache -h <Enter>
Usage: apache [-D name] [-d directory] [-f file] [-n service]
              [-C "directive"] [-c "directive"] [-k signal]
              [-v] [-V] [-h] [-l] [-L] [-S] [-t] [-T]
  -D name          : define a name for use in <IfDefine name> directives
  -d directory     : specify an alternate initial ServerRoot
  -f file          : specify an alternate ServerConfigFile
  -C "directive"   : process directive before reading config files
  -c "directive"   : process directive after  reading config files
  -v               : show version number
  -V               : show compile settings
  -h               : list available command line options (this page)
  -l               : list compiled-in modules
  -L               : list available configuration directives
  -S               : show parsed settings (currently only vhost settings)
  -t               : run syntax check for config files (with docroot check)
  -T               : run syntax check for config files (without docroot check)
  -n name          : name the Apache service for -k options below;
  -k stop|shutdown : tell running Apache to shutdown
  -k restart       : tell running Apache to do a graceful restart
  -k start         : tell Apache to start
  -k install   | -i: install an Apache service
  -k config        : reconfigure an installed Apache service
  -k uninstall | -u: uninstall an Apache service
  -W service       : after -k config|install; Apache starts after 'service'
  -w               : holds the window open for 30 seconds for fatal errors.
To configure Apache in general

Apache is configured by placing directives in plain text configuration files. The main configuration file is usually called httpd.conf, which is by default placed in the subdirectory Apache\conf\.

To know how to use directives in httpd.conf, while Apache is running, visit http://localhost/manual/ in IE. You will see the documentation associated with Apache. Click "Run-time Configuration Directives" under "Reference Manual" and you will have the list of directives available in the standard Apache distribution listed there. You may have the detailed explanation of the usage of each directive by clicking the corresponding link. For example, if you choose Port directive, you will have:

 
Port directive
Syntax: Port number
Default: Port 80
Context: server config
Status: core

Number is a number from 0 to 65535; some port numbers (especially below 1024) are reserved for particular protocols. See /etc/services for a list of some defined ports; the standard port for the http protocol is 80.

......

Read httpd.conf configuration file and make sure you understand at least the following directives used there:
 
ServerRoot
MaxKeepAliveRequests
KeepAliveTimeout
Listen
BindAddress
Port
ServerName
DocumentRoot
DefaultType
<Directory>
CacheRoot
ErrorLog
LogFormat
ErrorDocument
NameVirtualHost
<VirtualHost>
<IfModule>
Order
Allow
Deny
AuthType
AuthUserFile
AuthName
To enable access control with Apache

1. Do some research work first and make sure you know how to use <Directory>, AuthType, AuthUserFile, AuthName, Order, Allow, and Deny directives and htpasswd tool in the subdirectory Apache\bin.

2. Create a directory controlled in Apache\htdocs and put some HTML files in it.

3. Configure Apache so that only some specific users (for example, a user named good can while another named bad cannot) can visit those HTML files in 2, while anyone can access any other file that originally exists in Apache\htdocs.
 

To configure Apache as a proxy

1. Enable the following directives by removing the starting # of the corresponding lines in httpd.conf:

 
LoadModule proxy_module modules/mod_proxy.so

...

AddModule mod_proxy.c

...

<IfModule mod_proxy.c>
    ProxyRequests On

    <Directory proxy:*>
        Order deny,allow
        Allow from all
    </Directory>

    ProxyVia On

    CacheRoot "C:/temp/Apache/proxy"
    CacheSize 5
    CacheGcInterval 4
    CacheMaxExpire 24
    CacheLastModifiedFactor 0.1
    CacheDefaultExpire 1
</IfModule>
 

2. Configure IE to use the Apache proxy server to surf the Internet.
.
3. User IE to visit any website, then check what appears in the subdirectory C:\temp\Apache\proxy\.
4. Configure Apache so that only some specific users can use the proxy service.

To set up virtual hosts with Apache

1. First make sure you know what name-based virtual hosts mean and how to use NameVirtualHost and <VirtualHost> directives.
2. Configure Apache by altering httpd.conf so that different web pages will be displayed when a user visits http://localhost/ and http://mycomputer/ (suppose the name of the current PC is  mycomputer) respectively.



© Jinzhong Niu, 2004