Darkhttpd – Run Simple and Secure Web Server Quickly

Darkhttpd might not have the webserver strides and reputation like Apache, Nginx, and Lighttpd but it is every front-end web developer’s best friend. It is the perfect web server for web developers or users in a hurry. It is lightweight, easy to set up, and launch.

This tutorial guide will walk us through the installation and configuration of Darkhttpd on your Linux operating system distribution.

Darkhttpd Features

Before we meet the objective of this article, let us first highlight some prominent Darkhttpd features.

  • You don’t need to be an advanced Linux user to set up Darkhttpd. It is a single binary, standalone, and does not require a user to interact with any configuration file.
  • This web server is efficient and portable due to the use of the C programming language in its development.
  • Small memory footprint.
  • Less than 100KB Docker image which is significantly small.
  • Depending on the Host header, darkhttpd can easily serve 301 redirects.
  • Supports If-Modified-Since, IPv6, HEAD requests and HTTP GET, and Keep-Alive connections.
  • Supports partial content/range which is useful when resuming a download or streaming media files.
  • Generates directory listings.

Darkhttpd Security

Understanding the security feature footprints of the webserver you are using is very important. A breakdown of what darkhttpd offers in terms of security is as follows:

  • Drops overly long requests.
  • Impervious to /../ sniffing.
  • Can chroot.
  • Times out idle connections.
  • Can drop privileges.
  • Can log accesses with inclusion to User-Agent and Referer.

Darkhttpd Limitation

With all the features and security footprints paraded by Darkhttpd, we however have to deal with its limitation to serving static content and not CGI (Computer-Generated Imagery).

Installing Darkhttpd Web Server in Linux

To install and put this lightweight webserver to the test, make sure your Linux operating system has the needed build tools and Git installed.

On RHEL, Rocky and AlmaLinux

$ sudo yum update
$ sudo yum groupinstall "Development Tools"
$ sudo yum install git

On Fedora

$ sudo dnf update 
$ sudo dnf groupinstall "Development Tools"
$ sudo dnf groupinstall "C Development Tools and Libraries"
$ sudo dnf install git

On Debian, Ubuntu and Mint

$ sudo apt update
$ sudo apt install build-essential
$ sudo apt install git

On Arch Linux

$ sudo pacman -Syyu
$ sudo pacman -S base-devel
$ sudo pacman -S git

On OpenSUSE

$ sudo zypper update 
$ sudo zypper install -t pattern devel_C_C++
$ sudo zypper install git

Next, clone the Darkhttpd repository from Github.

$ git clone https://github.com/ryanmjacobs/darkhttpd

Navigate to the darkhttpd directory and build it.

$ cd darkhttpd
$ make
Install Darkhttpd in Linux
Install Darkhttpd in Linux

How to Use Darkhttpd Web Server in Linux

To use darkhttpd, we simply need to point to the directory containing the web files we need to serve.

$ ./darkhttpd /var/www/html/linuxshelltips.lan.network
Run Darkhttpd in Linux
Run Darkhttpd in Linux

Navigating to the following URL will serve your web pages:

http://linuxshelltips.lan.network:8080 
or 
http://127.0.0.1:8080
Serve Webpages Using Darkhttpd
Serve Webpages Using Darkhttpd

To use a different port, adhere to the following darkhttpd command usage:

$ ./darkhttpd /var/www/html/linuxshelltips.lan.network --port 8081

To limit the number of simultaneous connections to 5:

$ ./darkhttpd /var/www/html/linuxshelltips.lan.network --maxconn 5

To use another file like home.htm as the index file:

$ ./darkhttpd /var/www/html/linuxshelltips.lan.network --index home.htm

To combine both port and bind-address:

$ ./darkhttpd /var/www/html/linuxshelltips.lan.network --port 8081 --addr 192.168.100.10

To view all other commands associated with Darkhttpd:

$ ./darkhttpd

For Debian-based users, you can alternatively generate the Debian package of darkhttpd after cloning it and then afterward install it like any other .deb package:

$ git clone https://github.com/ryanmjacobs/darkhttpd 
$ cd darkhttpd 
$ make debian 
$ sudo dpkg -i darkhttpd.deb

Darkhttpd is the go-to web server for testing the responsiveness of your web-based project GUI before hosting it in a production environment. It is fast, simple, and easy to use.

1 thought on “Darkhttpd – Run Simple and Secure Web Server Quickly”

Got something to say? Join the discussion.

Have a question or suggestion? Please leave a comment to start the discussion. Please keep in mind that all comments are moderated and your email address will NOT be published.