Forum

Darkhttpd-Ultra-sma...
 
Notifications
Clear all
1 Posts
1 Users
0 Likes
5,724 Views
Posts: 108
Topic starter
(@taichi)
Member
Joined: 4 years ago

Darkhttpd server is a very small static http server, only 36KB after compilation, but it can complete the functions of ftp and http.

darkhttpd-1.12.tar.bz2 (20,184 bytes)
or: darkhttpd.c
or: git clone https://unix4lyfe.org/git/darkhttpd  (http works too)
or: browse the darkhttpd gitweb.

Features:

  • Simple to set up:
    • Single binary, no other files, no installation needed.
    • Standalone, doesn't need inetd or ucspi-tcp.
    • No messing around with config files - all you have to specify is the www root.
  • Written in C - efficient and portable.
  • Small memory footprint.
  • Event loop, single threaded - no fork() or pthreads.
  • Generates directory listings.
  • Supports HTTP GET and HEAD requests.
  • Supports Range / partial content. (try streaming music files or resuming a download)
  • Supports If-Modified-Since.
  • Supports Keep-Alive connections.
  • Supports IPv6.
  • Can serve 301 redirects based on Host header.
  • Uses sendfile() on FreeBSD, Solaris and Linux.
  • Can use acceptfilter on FreeBSD.
  • At some point worked on FreeBSD, Linux, OpenBSD, Solaris.
  • ISC license.
  • suckless.org says darkhttpd sucks less.

Security:

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

Limitations:

  • Only serves static content - no CGI.

 

How to compile darkhttpd?
---------------------
Install git on the server first, then get all the files:

yum install git -y #centos use
apt-get install git -y #debian use

---------------------
The following is the universal installation code:

git clone https://github.com/4kercc/darkhttpd.git # Then get all files
cd darkhttpd #Enter the directory
make #Compile

This completes the installation. Is not it simple?.

It will be easier to use in the future, because you have already compiled it, save a copy of the darkhttpd file in the / darkhttpd / directory, and use it directly next time (don't forget the permissions.)

The easiest way to use:

./darkhttpd / root --port 8081 --daemon

I explain this sentence.

./darkhttpd #Run darkhttpd service
/ root #darkhttpd server's main directory location
--port 8081 #access port, generally use 80, but as you wish , other ports need ip + port access
--daemon # background

Other functions:

--------------------

Serve / var / www / htdocs on the default port (80 runs as root, otherwise 8080):

$ ./darkhttpd / var / www / htdocs

Serve on port 8081 ~ / public_html:

$ ./darkhttpd ~ / public_html --port 8081

Only bind to one IP address (useful on multi-homed systems):

$ ./darkhttpd ~ / public_html --addr 192.168.0.1

Up to 4 connections can be connected at the same time:

$ ./darkhttpd ~ / public_html --maxconn 4

Log access file:

$ ./darkhttpd ~ / public_html --log access.log

Chroot For additional security (you need root permission chroot):

$ ./darkhttpd / var / www / htdocs --chroot

Use default.htm instead of index.html:

$ ./darkhttpd / var / www / htdocs --index default.htm

Add mimetypes-in this case, provide the .dat file as text / plain:

$ cat extramime
text / plain dat
$ ./darkhttpd / var / www / htdocs --mimetypes extramime

Remove permissions:

$ ./darkhttpd / var / www / htdocs --uid www --gid www

Use acceptfilter (FreeBSD only):

$ kldload accf_http
$ ./darkhttpd / var / www / htdocs --accf

Run in the background and create a pidfile:

$ ./darkhttpd / var / www / htdocs --pidfile /var/run/httpd.pid --daemon

Web forwarding (301) requests some hosts:

$ ./darkhttpd / var / www / htdocs --forward example.com http://www.example.com \
--forward secure.example.com https://www.example.com/secure

Web forwarding (301) requests all hosts:

$ ./darkhttpd / var / www / htdocs --forward example.com http://www.example.com \
--forward-all http://catchall.example.com

Command line options can be combined:

$ ./darkhttpd ~ / public_html --port 8080 --addr 127.0.0.1

To view the complete list of command line options, run darkhttpd without any parameters:

$ ./darkhttpd

---------------------

This server can be integrated with the webui of aria2, so that the download pressure of aria2 can be dispersed. Aria2 uses port 6800, and darkhttpd uses port 6801, and can build online webui. Of course, specific interests can be studied on their own. This darkhttpd function is far more powerful than imagined.

Topic Tags
Share: