tHttpd "how to" -- Tiny Web Server



Home


If you are looking for a tiny, fast and secure web server and do not want to spend a lot of time setting it up, then you may want to check out tHttpd. This tiny web server requires almost no setup time and you can configure and run it in one line.



Building the binary

To get started, you can download the source from ACME.com or download the package for tHttpd for your type of operating system. Most OSs have pre made RPM's or DEB's for example. Something like "yum install thttpd" for RedHat or "apt-get thttpd" for debian will fetch the packages for you.



Starting the daemon

Once installed, the following will start tHttpd chrooted to the /var/www/htdocs/ directory and serve out data from the same directory. The daemon will run on port 80 by default.

/usr/local/sbin/thttpd -r -d /var/www/htdocs/



Finished

Thats about it. The daemon will run with the minimum of fuss. The tHttpd daemon is perfect for simple web servers and can be used as a fast way to setup a file server. You will notice that if thttpd does not find an index.html file in a directory it will dynamically generate a file listing of that directory. This might be useful for a small home LAN or a file server for a corporate network. You might use thttpd to offload static images from an Apache server or setup a private web page for friends and family.



Options

Other options you may be interested in adding to the line above may include:

-u tiny_user   This will run the daemon as the user listed here if the daemon is started as root. By default the daemon is run as "nobody" if root starts it. For this example the daemon will run as the "tiny_user" user.

-M 3600   Specifies the number of seconds to be used in a "Cache-Control: max-age" header to be returned with all responses. An equivalent "Expires" header is also generated. This will help reduce the amount of traffic to the site for objects the clients already have a copy of. This example will set the max-age and expires headers to 3600 seconds or one(1) hour.



Questions?

I get an "access denied" error when trying to download files! Whats wrong?

The thttpd server will not allow you to download files that have the execute bit set on them. The theory is this is a script or program the daemon is using is in that directory and should not be shared with web server clients. To fix this, make sure the files you want to serve out are set with the permissions of 644 . In other words make sure that the user the daemon is running as is only allowed "read" access to the files you want to allow downloaded.



Questions, comments, or suggestions? Contact Calomel.org