Help File Library: Configuring kHTTPd NHF
Written By: Evan Thompson <
evaner@bigfoot.com>
NOTE: This Help File only applies to those running 2.4.x (or newer
2.3.x) kernels. Those with 2.2.x or older kernels must upgrade before
continuing.
BE WARNED: kHTTPd is still experimental, so it's not my fault if
something breaks. Blame it on...er...uh...Linus!
What is kHTTPd?
kHTTPd is a webserver that handles only static (file based, non-cgi/php)
webpages, and passes all requests for non-static (dynamic) information to
a regular userspace-webserver such as Apache or Zeus. This is benificial
because it offloads the delivery of static webpages to the kernel,
allowing the userspace-webserver program (such as apache) to do what it
does best: deliver dynamic contenet (cgi-bin, php). In a nutshell, it
makes your webserver work faster, which means you can serve up more
pr0n err, useful files faster...yes...heh heh heh.
Getting it into the kernel:
You've got your shiny new 2.4.x kernel, and now you want to get kHTTPd
working. There are two ways to compile kHTTPd into the kernel. Directly
or as a module. I suggest compiling it in directly because modules cause
overhead, but do as you wish. If you don't know how to compile a kernel,
then you should take a look at the Kernel
Compling Help File first.
The kHTTPd option can be found under:
Networking options ---> Kernel httpd acceleration
(EXPERIMENTAL)
Enable it, (re)compile your kernel, install it properly and reboot...
Getting it to work:
...ah, but you see, it's not that easy! Now we must configure it. This
is where it gets pretty hard. Make sure nobody's downloading a big file
off your webserver, 'cause you're going to kick them off soon. First,
what we need to do is create a script so that this crazy thing will start
and stop. Because of the different type of init scripts, this may not
work exactly as I write it out, but I'll try to be kind to the distros
that I've used in the past.
Create a new file in /etc/init.d (if you use Debian, /etc/rc.d/init.d if
you use Red Hat or Mandrake(?), /etc/rc.d if you use Slackware) called
khttpd. Replace the stuff in red with the appropriate configuration.
#!/bin/sh
case "$1" in
start)
echo -n "Starting kHTTPd webserver:"
# Don't include the next line if you didn't compile it as a
module.
modprobe khttpd
echo -n " khttpd"
echo port apache is running on (usually 8080
-- you'll see later) > /proc/sys/net/khttpd/clientport
echo port kHTTPd should run on (usually
80) > /proc/sys/net/khttpd/serverport
echo your document root (usually
/var/www) > /proc/sys/net/khttpd/documentroot
echo suffixes that are dynamic (for example,
php3 shtml) > /proc/sys/net/khttpd/dynamic
echo 1 > /proc/sys/net/khttpd/start
echo "."
;;
stop)
echo -n "Stopping kHTTPd webserver:"
echo 1 > /proc/sys/net/khttpd/unload
echo -n " khttpd"
# Don't include the next line if you didn't compile it as a
module.
rmmod khttpd
echo "."
;;
reload)
echo -n "Reloading kHTTPd webserver:"
echo -n " khttpd"
echo 1 > /proc/sys/net/khttpd/stop
echo 1 > /proc/sys/net/khttpd/start
echo "."
;;
force-reload)
$0 reload
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage: /path/where/you/put/this/script/khttpd
{start|stop|reload|restart}"
exit 1
;;
esac
exit 0
BE SURE TO chmod 755 khttpd BEFORE YOU CONTINUE
Then, you must configure Apache or whatever other webserver you are using
to use port 8080, otherwise you'll have two programs trying to serve to
port 80, and that's not good. For Apache, in httpd.conf, you must
change:
Port 80
to
Port 8080
I'm not sure how to change the port for other servers. Check your
webserver documentation for more information. It should be there.
And now, we must add the appropriate symlinks. Again, this is different
for the different distributions, so check the documentation for sysvinit
on your system to see exactly how to do this. For Debian, you can use the
handy-dandy update-rc.d tool by typing:
update-rc.d khttpd defaults
For Red Hat or Mandrake, you must do the following:
ln -s /etc/rc.d/init.d/khttpd /etc/rc.d/rc3.d/S20khttpd
ln -s /etc/rc.d/init.d/khttpd /etc/rc.d/rc5.d/S20khttpd
ln -s /etc/rc.d/init.d/khttpd /etc/rc.d/rc0.d/K20khttpd
ln -s /etc/rc.d/init.d/khttpd /etc/rc.d/rc1.d/K20khttpd
ln -s /etc/rc.d/init.d/khttpd /etc/rc.d/rc2.d/K20khttpd
ln -s /etc/rc.d/init.d/khttpd /etc/rc.d/rc6.d/K20khttpd
If you are using Slackware, you can either create init.d and rc0.d
through to rc6.d in /etc/rc.d and follow the instructions for Red Hat (make
sure you move khttpd to /etc/rc.d/init.d then), or you can add to the top
of /etc/rc.d/rc.httpd after the #!/bin/sh the following:
/etc/rc.d/khttpd start
I'd suggest you to use the Red Hat method if you are using Slackware until
I figure out how to get it to stop at shutdown (if you know how, could
you please
e-mail me).
Starting it up:
You're done, almost! Now, all you have to do is restart your webserver
and start up kHTTPd. You can either reboot (not a good idea unless you
want to), or you can do the following:
For Debian:
/etc/init.d/apache restart
For Red Hat:
/etc/rc.d/init.d/apache restart
For Slackware:
/var/lib/apache/sbin/apachectl restart
Then type:
/path/where/you/put/this/script/khttpd
start
and there you go. If you get any errors, make sure you have done
everything that is mentioned here, then you may complain to
me. If you want more information,
you can reading it in the kHTTPd README (that's where I got most of my
info) found at
/usr/src/linux/net/khttpd/README.