this is obsolete doc -- see http://doc.nethence.com/ instead

thttpd configuration 

 

<img src="/images/bill.gif" /> 

 

Installation 

Fetch and extract, 

wget http://acme.com/software/thttpd/thttpd-2.27.tar.gz
tar xzf thttpd-2.27.tar.gz
cd thttpd-2.27/

 

Eventually change the default green background to white, 

grep -ri color *
vi libhttpd.c

and clean up the <body> tags (two occurences). 

 

Note. one could also edit the defaults, 

#vi config.h

but they're fine. Even INDEX_NAMES eventually points to index.cgi, already. 

 

Create the needed groupthttpd user and group, 

groupadd www

note. otherwise you would get this error doing 'make install', 

chgrp: invalid group: `www'

 

Compile and install, 

./configure
make clean
make
make install

 

Troubleshooting installing 

You may have to, 

#mkdir -p /usr/local/man/man1/

 

If you get this error doing 'make', 

htpasswd.c:52: error: conflicting types for 'getline'

replace 'getline' by 'my_getline' in extras/htpasswd.c (two occurences). 

 

Configuration 

Create the web dir and some user, 

mkdir -p /tftpboot/
useradd -g www -d /tftpboot/ -s /sbin/nologin www

 

Configure thttpd, 

vi /etc/thttpd.conf

like, 

dir=/tftpboot
chroot
user=www
logfile=/var/log/thttpd.log
pidfile=/var/run/thttpd.pid

other options, 

vhost
charset=utf-8
cgipat=**.cgi

Note. other charsets: 8859-1, 8859-15 

 

If using vhost, create a virtual host, 

mkdir /var/www/host.example.net/

 

Note. directory listing is enabled as long the directory has the 'x' permission 

 

Virtual host redirects & tricks 

It's clever to make a redirect for: 

- your server's hostname, 

- your server's IP address, 

- the global domain name, 

to the main website it is supposed to be hosting, so you will get even more traffic on it. So people looking for your hostname, domain or IP directly will get a clue on your business or what you are doing, and won't fall on some 404 because the virtual host directory doesn't exist. So create redirects like this, 

mkdir example.net/
cd example.net/
cp path/to/thttpd/redirect redirect.cgi
ln -s redirect.cgi index.html
cat > .redirects <<EOF9
/               http://www.example.net/
ln -s example.net server_host.example.net
ln -s example.net IP_ADDRESS

Note. Make sure you have got 'cgipath=**.cgi' in your thttpd configuration. 

 

Usage 

Start the daemon, 

thttpd -C /etc/thttpd.conf

enable it at boot time, 

cat >> /etc/rc.local <<EOF9
echo -n Starting thttpd...
/usr/local/sbin/thttpd -C /etc/thttpd.conf && echo done
EOF9

 

Check the vhost is working. Open your web browser to the URL e.g., 

http: //host.example.net

 

UTF8 encoding 

To serve UTF8 content you need several things: 

- charset=utf8 in thttpd.conf (otherwise charset="iso-8859-1" is the default), 

- the right http header for CGI scripts [e.g.](https://www.w3.org/International/O-HTTP-charset.fr.php), 

print "Content-type: text/plain; charset=utf-8\n\n";

then you should also make sure the libraries you are using are compatible with UTF8 e.g. perl [CGI and DBI modules aren't](http://dysphoria.net/2006/02/05/utf-8-a-go-go/).  

- or the right file encoding, html or text (this depends on your shell env and text editor compatibility with utf8). 

 

Todo 

Configure a minimal chrooted CGI environment, 

mkdir -p /var/www/bin/
cp /bin/ksh /var/www/bin/
cp /bin/cat /var/www/bin/
ldd /var/www/bin/ksh
ldd /var/www/bin/cat
...
mkdir tmp/
chmod 777 tmp
chmod +t tmp
(cd /; tar cvf - dev/tty) | (cd /var/www; tar xvf -)

test it, 

chroot /var/www /bin/ksh
cat <<EOF9
check
EOF9
exit