SETTING UP THTTPD

FROM SOURCE

vi libhttpd.c

eventually add index without extension

#define INDEX_NAMES "index", "index.html", "index.htm", "index.xhtml", "index.xht", "Default.htm", "index.cgi"

note index.cgi is already in the list

make text/html the default for serving files w/o extension

//char* default_type = "text/plain; charset=%s";
char* default_type = "text/html; charset=%s";

build

./configure
make -j8

install

grep ^www /etc/group
groupadd www

ls -ld /usr/local/man/man1/
mkdir -p /usr/local/man/man1/

make install

#grep ^nogroup /etc/group
#useradd -s /sbin/nologin -d /nonexistent -g nogroup -u 32766 thttpd

note nobody is the default user

useradd -s /sbin/nologin -d /nonexistent -r thttpd
grep ^thttpd /etc/group
grep ^thttpd /etc/passwd

NETBSD INSTALL

pkg_add thttpd

/usr/libexec/locate.updatedb
locate thttpd.conf
diff /usr/pkg/etc/thttpd.conf /usr/pkg/share/examples/thttpd.conf
mv /usr/pkg/etc/thttpd.conf /etc/
ln -s /etc/thttpd.conf /usr/pkg/etc/thttpd.conf

cp /usr/pkg/share/examples/rc.d/thttpd /etc/rc.d
echo thttpd=yes >> /etc/rc.conf

SETUP

cp -pi /etc/thttpd.conf /etc/thttpd.conf.dist
vi /etc/thttpd.conf

no vhosts

dir=/data/www/os3.su
logfile=/var/log/thttpd.log
pidfile=/var/run/thttpd.pid
port=80
user=thttpd
chroot

with vhosts and CGI

dir=/data/www
cgipat=**.cgi|/cgi-bin/*
logfile=/var/log/thttpd.log
pidfile=/var/run/thttpd.pid
port=80
user=thttpd
chroot
vhost

no need to specify charset, UTF-8 is (now?) the default

more options

# nosymlink# default = !chroot
# novhost
# nocgipat
# nothrottles
# host=0.0.0.0
# charset=iso-8859-1

READY TO GO

vi /etc/rc.local

echo -n thttpd...
/usr/local/sbin/thttpd -C /etc/thttpd.conf && echo done
ps auxww | grep thttpd | grep -v grep

ACCEPTANCE

curl -s localhost/

OPERATIONS

tail -F /var/log/thttpd.log                       

vi ~/RESTART-THTTPD 

#!/bin/sh

ps auxww | grep thttpd | grep -v grep
echo -n killing thttpd...
pkill thttpd && echo done

echo -n thttpd...
/usr/local/sbin/thttpd -C /etc/thttpd.conf && echo done
ps auxww | grep thttpd | grep -v grep

chmod +x RESTART-THTTPD 

and something about SIGHUP

ADDITIONAL NOTES

TLS

see stunnel

CHROOT + CGI

see diy chroot

REDIRECT

cp thttpd-2.29/cgi-src/redirect /data/www/redirect.cgi
chmod +x /data/www/redirect.cgi

configure the redirect patterns at the root of the data dir w/ or w/o chroot enabled (troubleshoot and find the exact path by test&try, looking at the 404 error message)

vi /data/www/.redirects

/*/*    https://nethence.com/
//.     https://nethence.com/

now choose what domains you need to redirect

ln -s redirect.cgi /data/www/noexist.nethence.com 

REDIRECT CUSTOM

unhappy with thttpd’s redirect? not flexible enough? try mine – sorry it is an HTML redirect, not a server-side HTTP

#!/bin/sh

cat <<EOF
Content-type: text/html

<!DOCTYPE html>
<html>
<head>
   <meta http-equiv="refresh" content="0; url=http://pub.nethence.com$SCRIPT_NAME">
</head>
</html>
EOF

RESOURCES

Configuration Options http://acme.com/software/thttpd/options.html

thttpd man page http://acme.com/software/thttpd/thttpd_man.html

thttpd notes http://acme.com/software/thttpd/notes.html

redirect man page http://acme.com/software/thttpd/redirect_man.html

thttpd https://en.wikipedia.org/wiki/Thttpd

A fork of Jef Poskanzer’s popular thttpd. https://github.com/blueness/sthttpd

+ssl

tiny / throttling / trivial HTTPd extended with proxy and TLS Pool support https://github.com/arpa2/thttpd-proxy-tlspool

Merecat ∴ Embedded Web Server https://github.com/troglobit/merecat


Nethence | Pub | Lab | Pbraun | SNE Russia | xhtml