Thttpd: Difference between revisions

From Leo's Notes
This page was last edited on 1 January 2022, at 06:38.
Initial Content
 
mNo edit summary
Line 46: Line 46:
# Move redirect to your web root. Call it <code>redirect.cgi</code>.
# Move redirect to your web root. Call it <code>redirect.cgi</code>.
# Symlink your source (for example, <code>index.html</code> if you want to redirect the root location) to <code>redirect.cgi</code>
# Symlink your source (for example, <code>index.html</code> if you want to redirect the root location) to <code>redirect.cgi</code>
# Add <code>/ <nowiki>http://somewhere.example.com/</nowiki></code> into <code>.redirects</code>.
# Add <code>/ <nowiki>http://somewhere.example.com/</nowiki></code> into <code>.redirects</code>.


== See also ==
== See also ==


* http://www.acme.com/software/thttpd/thttpd_man.html
* http://www.acme.com/software/thttpd/thttpd_man.html
*Merecat httpd - https://github.com/troglobit/merecat/

Revision as of 06:38, 1 January 2022

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 CCOPT='-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