Interpreting Web Server Log Files

 < Day Day Up > 

Expanding Apache's Capabilities with Modules

One of the nicest features of Apache is its modular plug-in design. Developers can easily expand the capabilities of the Apache web server without forcing the end users to recompile their server software or make complex configuration changes. In this section, we'll be looking at a handful of modules some included with Tiger, others that you'll need to download and compile. These are just a tiny sample of what is available for the world's most popular web server:

mod_dav Enables the WebDAV protocol for cross-platform sharing of files via HTTP

mod_mp3 Creates a SHOUTcast-compatible streaming MP3 server

mod_bonjour Advertises your Apache sites over the LAN using Apple's Bonjour technology

Mod_rewrite Rewrites local URLs based on regular expressions and can proxy remote content through a given URL


If you're interested in rebuilding Apache or enabling SSL support, you may be interested in the supplemental document Enabling Apache SSL Support, downloadable at

Sharing Files with WebDAV and mod_dav

Something that Apple hasn't advertised with Mac OS X is the integration of WebDAV as a native file-sharing format. If you're the proud owner of a .Mac account, you already use WebDAV to access your iDisk. WebDAV (Distributed Authoring and Versioning) is a relatively new protocol that operates on top of HTTP. What makes this attractive is the fact that it doesn't require additional xinetd or system daemons to be present, and works great through HTTP proxies.

WebDAV is entirely cross-platform, is integrated into the Windows operating system, and is supported natively in software such as Macromedia Dreamweaver MX. Using WebDAV, you can distribute authoring and editing websites across a number of different computers and operating systems or just use it to share files. Best of all, WebDAV is easy to use and, because it operates through Apache, the same configuration directives you've already seen can apply directly to its setup.

Configuring mod_dav

Apple includes a precompiled version of WebDAV in Tiger. To enable it, open your /etc/httpd/httpd.conf file and look for the two (nonconsecutive) lines:

 #LoadModule dav_module     libexec/httpd/ #AddModule mod_dav.c 

Uncomment both lines so that they read:

 LoadModule dav_module     libexec/httpd/ AddModule mod_dav.c 

To finish the configuration and activation of WebDAV service on your Apache server, you need to create a directory that will hold WebDAV lockfiles and then turn on the service for a particular directory or location.

Use the DAVLockDB directive to set the directory and base filename for WebDAV's lockfiles. This should fall anywhere after the LoadModule/AddModule lines in the /etc/httpd/httpd.conf file:

 DAVLockDB /var/tmp/davlock 

This example specifies that the directory /var/tmp will be used to hold lockfiles and that davlock will be the base filename for the lockfiles. Be sure to include the base filename, not just a directory name. If the lockfile is not properly set, mod_dav will start, but won't operate correctly.

Now choose one of the directory or container objects that will support WebDAV service and add the DAV On directive:

 <Directory "/Library/WebServer/Documents">    DAV On    Options Indexes FollowSymLinks MultiViews    AllowOverride None    Order allow,deny    Allow from all </Directory> 

You should limit access to the DAV services using the same require directive in the standard Apache configuration. WebDAV relies on the HTTP protocol to authenticate users for editing. That means that you will need to create a password file using htpasswd just as we did earlier or use Apple's authentication module to limit access to user accounts on the computer. Unlike the previous example, however, a valid user will be required only when performing a modification to the file system. To create this sort of selective authentication, we'll use the Limit directive. For example, the following configuration file fragment defines an authentication scheme and limits it to the operations that WebDAV uses to add and update files.

 AuthType Basic AuthName "The Poisontooth Webserver" AuthUserFile /Users/jray/webpasswords <Limit PUT DELETE PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>      Require valid-user </Limit> 

To finish things up, just combine the authentication block with the resource that WebDAV support has been enabled (DAV On):

 1: <Directory "/Library/WebServer/Documents"> 2:   DAV On 3:   Options Indexes FollowSymLinks MultiViews 4:   AllowOverride None 5:   Order allow,deny 6:   Allow from all 7:   AuthType Basic 8:   AuthName "The Poisontooth Webserver" 9:   AuthUserFile /Users/jray/webpasswords 10:   <Limit PUT DELETE PROPPATCH MKCOL COPY MOVE LOCK UNLOCK> 11:     Require valid-user 12:   </Limit> 13: </Directory> 

Line 1 sets up the directory to WebDAV-enable. This can be a directory that is already defined in the main Apache http.conf or one of the user configuration files.

Line 2 turns on DAV support, and lines 3 6 are standard directory security directives not WebDAV related.

Lines 7 9 set up basic HTTP authentication. This will be used to authenticate potential WebDAV clients. Lines 10 12 limit the HTTP authentication to only those actions that would be triggered by a WedDAV client.

One small thing still needs to be adjusted before WebDAV can be used: the permissions on the directory that has WebDAV support enabled. Because WebDAV is nothing more than an extension to Apache, it has no more user rights than the Apache server process. This means that if Apache can't write to a resource (that is, it isn't owned by www or isn't set to world-writable), WebDAV won't be able to modify the resource either. To make a directory editable using DAV, you must use chown to modify the file and directory ownership. Type chown -R www:admin <directory to DAV-enable> and you're done!

Restart Apache (sudo /usr/sbin/apachectl restart) to begin using WebDAV.

Mounting WebDAV Shares

First, from within a Finder window, use the Go menu to choose Connect to Server (Command-K). The dialog box shown in Figure 23.3 will appear.

Figure 23.3. Use the Connect to Server menu item to connect to WebDAV-enabled servers.

Fill in the URL of the directory with DAV access in the Address field. This should be the web path to the resource, not the actual file path on the server. In the screenshot shown, the main root directory of the web server has been enabled, so the URL given is just set to the main website URL. When satisfied that your settings are correct, click Connect. You will be prompted for a username and password for the resource. Use the username/password pair defined by your HTTP authentication configuration.

After a few seconds, the remote site should be mounted as if it were a local drive on your computer.


Although not entirely practical for high-volume sharing, WebDAV volumes work just like AppleShare or NFS volumes under Tiger. Unlike the implementation on certain other platforms, Tiger users can store and execute applications directly on WebDAV shares. In Mac OS X 10.2 and up, your iDisk is accessed entirely via the WebDAV protocol. This enables it to appear to be connected all the time. The end result is more convenient access for you and less of a load on Apple's servers.

Using WebDAV on Windows

Like Apple, Microsoft integrates WebDAV into the latest releases of their operating system. To access a WebDAV share on Windows XP, you must create a new Network Place.

Double-click My Network Places to open the Network Places window. Next, double-click Add Network Place to start the Add Network Place Wizard. If prompted, tell the Add Network Place Wizard to Choose Another Network Location, and then click Next. Windows will ask for the address of the network place, as shown in Figure 23.4.

Figure 23.4. The Add Network Place Wizard will help set up a WebDAV resource in Windows.

Fill in the URL of the WebDAV resource, but in a slightly different format than you did on Tiger. On Windows XP, you must supply the URL with the username and port included; for example, http://<username>@<>:80/<pathtoDAVshare>. After that has been entered, click Next. As with Tiger, you will be prompted for the username and password that were set using htpasswd or accessed by mod_auth_apple. Click Next to finish and mount the resource.

WebDAV support is an integral part of Mac OS X and Windows and can be used to unite a multiplatform environment for collaboration on websites and other projects. In a pinch, WebDAV can even serve as a file server for things other than web-related files.

Advertising Sites with mod_bonjour

Another module that Apple has included in Tiger (and neglected to tell anyone about) is its self-authored mod_bonjour module. mod_bonjour registers sites with Bonjour-enabled browsers (such as Safari) on your local network. Rather than bookmarking your local servers, the servers advertise their own bookmarks!

Unfortunately, Apple failed to provide a mechanism for disabling this so if you happen to be running a private test server, there's a good chance your machine is advertising it via Bonjour to every other computer on your network. Let's take a look at how you can manually control mod_bonjour and what it does.

Configuring mod_bonjour

To disable the module completely, just comment out the appropriate LoadModule and AddModule lines from /etc/httpd/httpd.conf:

 #LoadModule bonjour_apple_module libexec/httpd/ #AddModule mod_bonjour_apple.c 

If, instead, you prefer to control which services are advertised, find the mod_bonjour directive block at the end of httpd.conf. The default block should look like this:

 <IfModule mod_bonjour_apple.c> RegisterUserSite all-users RegisterDefaultSite </IfModule> 

There are two directives included within the block the first, RegisterUserSite all-users, registers all personal sites (~<username>) for users with configuration files within /etc/httpd/users. To register only specific user sites, use RegisterUserSite <username> [<username> ...]. The second directive, RegisterDefaultSite, registers the default /Library/Webserver/Documents website via Bonjour. A final directive, RegisterResource <resource name> <resource URI>, enables you to register any URL on your server with an arbitrary resource name.

For example, to register my personal website (username jray) along with a URL/bulletinboard/bbs.cgi, I'd change the Bonjour directives in /etc/httpd/httpd.conf to read:

 <IfModule mod_bonjour_apple.c> RegisterUserSite jray RegisterResource "My Local BBS" "/bulletinboard/bbs.cgi" </IfModule> 

After making the changes, restarting Apache puts them into effect immediately, removing the default site advertisement and adding my two custom Bonjour-enabled sites.

That's enough work for now. On to something a bit more entertaining streaming audio from Apache!

Creating a Streaming MP3 Station with mod_mp3

If you've been using iTunes, you've probably got quite a collection of MP3 files built up on your drive. Rather than taking the MP3s with you wherever you go, you can create your own Internet radio station and broadcast music to your computer at work, home, or wherever your MP3s aren't. Apple briefly introduced this feature with iTunes 4.0, and then removed it because of pressure from the recording industry.

Using the Apache mod_mp3 module, you bring this feature back in the form of a SHOUTcast-compatible streaming MP3 server. Of course, it goes without saying that anyone who listens to your streams has a legitimate copy of the music. Absolutely no sarcasm intended. None.

Installing mod_mp3 only takes a few minutes of time. Download the latest release from and then unarchive and cd into the distribution directory. Now use configure --with-apxs to prepare the module:

 brezup:jray jray $ cd mod_mp3-0.40 brezup:jray mod_mp3-0.40 $ ./configure --with-apxs ARGS --with-apxs  checking for ghttp for yp.. could not find ghttp for yp support checking for perl.. found checking for apxs.. found adding support for internal dispatch Writing proto.h Writing Makefile ... 

Next, type make to compile:

 brezup:jray mod_mp3-0.40 $ make `/usr/sbin/apxs -q CC` -I`/usr/sbin/apxs -q INCLUDEDIR` `/usr/sbin/apxs -q   CFLAGS` -DCONTENT_DISPOSITION -DSELECT_ENABLED  -c src/mod_mp3.c   -DCONTENT_DISPOSITION -DSELECT_ENABLED  -o src/mod_mp3.o  `/usr/sbin/apxs -q CC` -I`/usr/sbin/apxs -q INCLUDEDIR` `/usr/sbin/apxs -q   CFLAGS` -DCONTENT_DISPOSITION -DSELECT_ENABLED  -c src/directives.c   -DCONTENT_DISPOSITION -DSELECT_ENABLED  -o src/directives.o  `/usr/sbin/apxs -q CC` -I`/usr/sbin/apxs -q INCLUDEDIR` `/usr/sbin/apxs -q   CFLAGS` -DCONTENT_DISPOSITION -DSELECT_ENABLED  -c src/ice.c   -DCONTENT_DISPOSITION -DSELECT_ENABLED  -o src/ice.o  `/usr/sbin/apxs -q CC` -I`/usr/sbin/apxs -q INCLUDEDIR` `/usr/sbin/apxs -q   CFLAGS` -DCONTENT_DISPOSITION -DSELECT_ENABLED  -c src/load.c   -DCONTENT_DISPOSITION -DSELECT_ENABLED  -o src/load.o   ... 

Finally, use sudo make install to add the module to /etc/httpd/httpd.conf:

 brezup:jray mod_mp3-0.40 $ sudo make install /usr/sbin/apxs -c -I`/usr/sbin/apxs -q INCLUDEDIR` src/mod_mp3.o   src/directives.o src/ice.o src/load.o src/shout.o src/utility.o   src/ogg.o src/common.o src/id3.o src/log.o src/internal_dispatch.o   src/encode.o cc -bundle -undefined suppress -flat_namespace -Wl,-bind_at_load -o   src/ src/mod_mp3.o src/directives.o src/ice.o src/load.o   src/shout.o src/utility.o src/ogg.o src/common.o src/id3.o   src/log.o src/internal_dispatch.o src/encode.o  /usr/sbin/apxs -i -a -n 'mp3' src/ ... +--------------------------------------------------------+ | All done.                                              | | If you want to use the default mod_mp3 configure file  | | go add:                                                | |                                                        | | Include /private/etc/httpd/mp3.conf                    | |                                                        | | to your httpd.conf for apache.                         | | If not, cat its content into your httpd.conf file.     | |                                                        | | Thanks for installing mod_mp3.                         | +--------------------------------------------------------+ 

The MP3-streaming module is now installed and ready for use.


Modules that are installed using the apxs utility, such as mod_mp3 are automatically placed in the appropriate location and have the appropriate LoadModule and AddModule directives added to the http.conf file.

Configuring mod_mp3

The mod_mp3 module is activated by setting up an Apache virtual host that will serve as the contact point for iTunes or any other streaming MP3 client. There are two ways to approach this: either by using a name-based or IP-based host, as you've already seen, or by using a virtual host running on a port address rather than the standard web server port 80. We'll use the latter approach.

A handful of directives are used to control the mod_mp3 streaming features. Several of these are documented in Table 23.4.

Table 23.4. These Directives Control mod_mp3's Capability to Stream Music



MP3 <file or pathname>

Adds an MP3 file or directory containing MP3 files to the list of files to be served.

MP3Engine <on|off>

Turns on the streaming engine.

MP3CastName <stream>

Sets a name for the streaming music.

MP3Genre <stream genre>

Sets a music genre for the stream.

MP3Random <on|off>

Randomizes the order that MP3 files will be served.

MP3Loop <on|off>

Loops through the music files indefinitely.

MP3LimitPlayConnections<connection limit>

The number of simultaneous streaming connections that will be supported.

MP3ReloadRequest <on|off>

If turned on, mod_mp3 will reload all files with each request. This is useful if you're adding to the available files during the broadcast.

MP3Playlist <playlist file>

Accepts the name of a file that contains a list of MP3 filenames.

MP3Cache <on|off>

When on, the module will attempt to cache all MP3 files in memory. This can speed up the server, but will probably take up way too much memory if you have more than a handful of files.

Use these directives, coupled with a virtual host, to set up and start streaming. The following is a typical sample virtual host entry for the /etc/httpd/httpd.conf file:

 1: Listen 8000 2: <VirtualHost> 3:   ServerName 4:   MP3Engine On 5:   MP3CastName "Johns Tunes" 6:   MP3Genre "Hard Rock and 80s" 7:   MP3 /Users/jray/Music 8:   MP3Random On 9:   Timeout 1200 10: </VirtualHost> 

Line 1 sets the port number for listening to incoming streaming requests. The default web port is 80, so if you're using the hostname for a website as well as streaming music, be sure to pick a different port.

Line 2 sets up the virtual host and port number for connections.

Line 4 turns on MP3 support.

Lines 5 and 6 set some identifying information for the streaming server.

Line 7 adds a directory containing MP3 files to the stream (you can add as many MP3 directives as you'd like).

Line 8 randomizes the playback order.

Line 9 sets a high timeout so that connections are properly serviced.


A sample mod_mp3 configuration is installed under the filename /etc/httpd/mp3.conf. Feel free to use it rather than typing out all the directives by hand.

Restart Apache to turn on your new mod_mp3-streaming server: /usr/sbin/apachectl restart.


Starting the Apache web server with mod_mp3 and a reasonably sized MP3 collection can take several seconds. Don't worry if the system appears to stall momentarily.

To access your new MP3 server using iTunes, select Open Stream from the Advanced menu (Command-U) and enter the URL of your MP3 virtual host. The sample mod_mp3 configuration used in this chapter would be referenced with the URL, as shown in Figure 23.5.

Figure 23.5. Open the Apache-served MP3 stream from within iTunes.


If you'd like to try another method of streaming MP3s, there are quite a few available (including Apple's own QuickTime Streaming Server available at Here are a few you might be interested in checking out:

SHOUTcast An official SHOUTcast server from nullsoft. Uses a command-line interface, but is fast and effective.

NetJuke NetJuke provides a web interface (PHP-based) to your music collection. This very popular open source project is extremely flexible and, after is has been installed, offers a wonderful web-based interface that you can access anywhere.

LeanStream A drag-and-drop approach to MP3 streaming, LeanStream is very easy to set up and use. Although not as configurable as other streaming servers, it can get your collection online in a flash.

MP3 Sushi An excellent Bonjour-enabled streaming server for Mac OS X. If you're not interested in tons of bells and whistles, but want a great interface to streaming music, this is it.

Transparent Proxying with mod_rewrite

Apache and its associated modules can be configured to do some reasonably amazing things. As one more useful example, I offer up these two configuration lines that you can add to your /etc/httpd/httpd.conf file (after the <Directory /> container is a good place):

 RewriteEngine On RewriteRule (.+\.pdf)\.html{HTTP_HOST}$1 [P] 

So, what does this code do? First, it activates the Apache mod_rewrite module, and then adds a rule to which Apache will compare every incoming request.

Assume that you have a PDF file on your site named mydocument.pdf. You want to serve the document online as HTML. You could convert it with a third-party piece of software or use an online PDF conversion service such as This rule automates the process by looking for requests for mydocument.pdf.html (which doesn't exist). If it sees a matching request, it immediately sends the corresponding PDF file to the online conversion service, and then returns the results back to your browser entirely transparently.

From the user's perspective, the file mydocument.pdf.html exists and is served from your web server.

The mod_rewrite module enables you to rewrite, redirect, and proxy remote servers through Apache using regular expressions. A complete guide to the many useful and varied features of this module is available at

     < Day Day Up > 

    Mac OS X Tiger Unleashed
    Mac OS X Tiger Unleashed
    ISBN: 0672327465
    EAN: 2147483647
    Year: 2005
    Pages: 251 © 2008-2017.
    If you may any questions please contact us: