LinuxCommandLibrary

darkhttpd

Serve files via a simple web server

TLDR

Start server serving the specified document root

$ darkhttpd [path/to/docroot]
copy

Start server on specified port (port 8080 by default if running as non-root user)
$ darkhttpd [path/to/docroot] --port [port]
copy

Listen only on specified IP address (by default, the server listens on all interfaces)
$ darkhttpd [path/to/docroot] --addr [ip_address]
copy

SYNOPSIS

darkhttpd [-a address] [-b backlog] [-c maxconns] [-d] [-E var=value] [-h] [-i index] [-l logfile] [-m mimetypes] [-p port] [-P pidfile] [-s] [-t maxbody] [-u user] [-v] [-V] directory

PARAMETERS

-a address
    Bind to specific IP address (default: all interfaces)

-b n
    Listen backlog size (default: 1024)

-c n
    Max simultaneous connections (default: 512)

-d
    Daemonize (fork to background)

-E var=value
    Set CGI environment variable

-h
    Show help and exit

-i file
    Default index file (default: index.html)

-l logfile
    Log to file (default: stderr)

-m mimetypes
    MIME types config file

-p port
    TCP port to listen on (default: 8080)

-P pidfile
    Write PID to file

-s
    Log to syslog instead of stderr

-t n
    Max request body size in bytes (default: 1048576)

-u user
    Drop privileges to user after binding port

-v
    Increase verbosity

-V
    Show version and exit

DESCRIPTION

Darkhttpd is a tiny, secure, single-threaded HTTP/1.0 server optimized for serving static files with minimal resource usage. Written in plain C by Emil Mikulic, its binary is under 100KB, making it perfect for embedded systems, quick LAN file sharing, documentation hosting, or as a drop-in replacement for heavier servers in low-traffic scenarios.

Key features include automatic directory indexing, customizable index files, MIME type support via file, basic CGI execution, privilege dropping for security, and logging options (stderr, file, or syslog). It binds to IPv4/IPv6, supports backlog tuning, connection limits to prevent abuse, and max body size restrictions. No database, scripting runtimes, or modules needed – just pure speed and simplicity.

Run it with darkhttpd /path/to/dir to serve on port 8080. Ideal for developers testing static sites or sysadmins exposing directories temporarily. Lacks HTTPS, dynamic content beyond CGI, and high concurrency (use nginx for that), but excels where footprint and startup time matter most.

Public domain software, portable across Unix-like systems.

CAVEATS

Single-threaded, so poor for high concurrency; no HTTPS/TLS; basic CGI only (no PHP/modular scripting); IPv6 support varies; requires read access to serve directory.

INSTALLATION

Most distros: apt install darkhttpd, yum install darkhttpd, or pkg install darkhttpd. Source: git clone https://github.com/emikulic/darkhttpd.git; make.

BASIC EXAMPLE

darkhttpd -p 8000 -d /var/www/html
Serves /var/www/html on port 8000 as daemon.

HISTORY

Created in 2004 by Emil Mikulic as a public domain alternative to bloated servers. Gained popularity in embedded Linux (OpenWRT, etc.) for its tiny size and speed. Sporadically updated; latest v1.13 (2017) adds IPv6 fixes and options.

SEE ALSO

thttpd(8), boa(8), nginx(8), httpd(8)

Copied to clipboard