Wednesday, February 27, 2008

Webserver in a NutShell

I've been playing around with the Debian-Installer recently, while setting up a live HDD.

The graphical installer lets you capture screen shots during the installation process, and I wanted to retrieve these to another PC. The way to do it is to switch to one of the virtual consoles, and launch the script httpd. With the webserver up and running, you can access to the box being installed over the network, using a web-browser, and download screenshots and log files.

You read it right. It's a webserver. Yup. Written in sh. Ain't it cool!? Well, granted, sockets are done using netcat and it isn't scalable, robust or flexible. But it serves its purpose, and it fascinates me in its simplicity. Is it crudeness that I mistake for genius? Maybe. I think it's neat.

I'm currently using a hacked version of this script at work, to serve a few static HTML pages. I had to modify the port being listened to from 80 to 8080 (the first is the default HTTP port, which is privileged, and thus can only be bind'ed by root). I also modified the web root directory to point to a directory in my user account, and added support for the text/html mime-type, by injecting the following bit into the large conditional statement at the end of the script:

elif [ "${page%.html}" != "$page" ]; then
header 200 "OK" "text/html"
You can use something similar to serve files with different extensions and mimetypes.

No comments:

Post a Comment