Thttpd

From Leo's Notes
Last edited on 1 January 2022, at 20:46.

thttpd is a simple, portable, and minimalistic HTTP server. More information from their home page at: http://www.acme.com/software/thttpd/

Compiling

thttpd can be compiled with plain build utilities. On Alpine Linux, run the following:

# apk add gcc musl-dev make

## Get thttpd and compile
# wget http://www.acme.com/software/thttpd/thttpd-2.29.tar.gz
# tar -xzvf thttpd-2.29.tar.gz
# cd thttpd-2.29

## Compile
# ./configure
# make CCOPT='-O2 -s -static' thttpd
# cd cgi-src
# make STATICFLAG='-O2 -s -static' all

Because the binary is compiled and linked statically, you can run thttpd within an empty container.

Usage

Description Command
Start thttpd on port 8080 serving /www thttpd -h 0.0.0.0 -p 8080 -d /www
Allow CGI anywhere thttpd -h 0.0.0.0 -p 8080 -d /www -c **
Log to stdout thttpd -h 0.0.0.0 -p 8080 -d /www -l -
Start thttpd using a configuration file thttpd -C thttpd.conf

Redirection

Redirections are handled by a separate CGI program. Included in the source tree is cgi-src/redirect.c which reads a .redirects file for the appropriate destinations.

To get this working:

  1. Compile cgi-src/redirect.c.
  2. Move redirect to your web root. Call it redirect.cgi.
  3. Symlink your source (for example, index.html if you want to redirect the root location) to redirect.cgi
  4. Add / http://somewhere.example.com/ into .redirects.

See also