How to make a webserver with lighttp and bash

Here is how to set up a minimalistic webserver, which uses bash as cgi.

Please note: Nothing has been done to make it secure, so it is probably INSECURE. It is probably also SLOW. DON'T use it for production projects!

If you are on Windows (as me), first download and install Cygwin.

Then download and install lighttp.

All you then need, is a lighttpd.conf file and an index.sh file.

Morten ~
$ cat lighttpd.conf
server.document-root = "/home/Morten/"

server.modules = ( "mod_cgi" )

index-file.names = ( "index.sh" )

cgi.assign = ( ".sh" => "/bin/sh" )

Morten ~
$ cat index.sh
#!/bin/sh

echo "Content-type: text/html"
echo ""

echo "Hello World" \
     "REQUEST_METHOD=$REQUEST_METHOD" \
     "QUERY_STRING=$QUERY_STRING" \
     "POST_DATA=`cat`"

Morten ~
$ /usr/sbin/lighttpd -f lighttpd.conf

Morten ~
$ curl 'localhost'
Hello World REQUEST_METHOD=GET QUERY_STRING= POST_DATA=

Morten ~
$ curl 'localhost?q=query'
Hello World REQUEST_METHOD=GET QUERY_STRING=q=query POST_DATA=

Morten ~
$ curl -d 'p=post' 'localhost'
Hello World REQUEST_METHOD=POST QUERY_STRING= POST_DATA=p=post

Kommentarer