installing nhttp

minimal http server

gentoo

the only place it is packaged.

emerge --ask app-eselect/eselect-repository
eselect repository add nburch git https://github.com/noahburchell/nburch-overlay.git
emaint sync --repo nburch
emerge --ask app-misc/nhttp
source

linux only. you need make and gcc or clang (c11, plus -fstack-clash-protection and -fcf-protection=full, so gcc 8+ or clang 11+).

get the source

grab the release tarball:

curl -LO https://github.com/noahburchell/nhttp/archive/refs/tags/v1.3.tar.gz
tar xf v1.3.tar.gz
cd nhttp-1.3

or clone the repo:

git clone --depth 1 https://github.com/noahburchell/nhttp.git
cd nhttp

build it

make
sudo make install

that puts the binary in /usr/bin. to put it somewhere else:

make install PREFIX="$HOME/.local" # make sure its in path

BINDIR and DESTDIR work too. make uninstall removes it, make clean drops the binary.

the hardening flags are set by the makefile and are not optional. CC, CFLAGS, CPPFLAGS and LDFLAGS are appended to, so overriding them is safe:

make CC=clang CFLAGS="-O3 -march=native"
usage
nhttp <docroot>

serves that dir. any dir path resolves to its index.html. GET and HEAD only, everything else is a 405.

it listens on port 80, so it needs root or the net_bind_service capability:

sudo setcap cap_net_bind_service=+ep /usr/bin/nhttp

that is the recommended way. nhttp does not drop privileges, so under sudo every forked request handler stays root.

the port, the 10s read/write timeout, the 8192 byte header cap and the 128 connection limit are compile-time constants. changing them means editing src/main.c and rebuilding. it is ipv4 only.