Do you have a site that is pushing only static content, a couple of .html or .swf files? Databasing is completely unnecesary for you and Apache seems to be eating alot of unnecessary PIDs and allocating alot of memory. Lighttpd (or more commonly known as Litey) is an ultra light weight and efficient webserver, purpose built to host static .html or download content.
I'll go ahead and walk you through installing this on a CentOS cloud server from a fresh install. Aside from installing it from source, it isn't that scary, we'll need to do a little bit of a dependency hunt, but its covered.
Contents |
//
So here we go, here is all the packages that you are going to need to install to get this running for you. Luckily CentOS, my free Redhat styled distro of choice has made the majority of your search easy by the use of Group installs. Is it more secure to install each package you'll need separately and not use the group installs??? Yes it is, but then you have to search through all the dependencies that you'll need by hand as well. That is the next step in this process once you feel comfortable installing and configuring Lighttpd.
# yum update
There are two Groups that we need to install to complete the Lighttpd install. I also included Editors, just cause I like the functionality of VIM over vi or nano. So the two necessaries are:
# yum groupinstall Editors "Development Tools" "Development Libraries"
This is the only dependency not provided through the above groups. You'll want to install "pcre" and its devel packages as well.
# yum install pcre-devel pcre
This section will go through preparing the install area to the actual build.
Technically you can install anywhere that you like, I generally will install in a tmp directory inside my home directory, so its easy to know what to delete later.
# mkdir ~/tmp
Download the most recent stable version, at the time of writing this article it was 1.4.22.
# cd ~/tmp/ # wget http://www.lighttpd.net/download/lighttpd-1.4.22.tar.gz # tar xzvf lighttpd-1.4.22.tar.gz # cd lighttpd-1.4.22/
If you've never built a package from source, its usually the same steps.
# ./configure
# make
# make install
# which lighttpd
This command will return a path to the now installed binary for the server
From here we are going to setup Lighttpd to start at boot and work with Virtual Hosts. Easy enough since most of the default settings that we want are assumed, the config file is going to very short compared to something like apache.
# mkdir -p /etc/lighttpd
Paste the bellow configurations into lighttpd.conf and edit as necessary to fit your needs.
## Lighttpd Configuration File ##
# Default Document Root
# This is the site that the server will revert to incase of an unknown Virtual Host
server.document-root = "/var/www/servers/example.com"
# Listening Port
server.port = 80
# Lighttpd User and Group
server.username = "www"
server.groupname = "www"
# Acceptable Mime types
mimetype.assign = (
".html" => "text/html",
".txt" => "text/plain",
".jpg" => "image/jpeg",
".png" => "image/png"
)
static-file.exclude-extensions = (".fcgi", ".php", ".rb", "~", ".inc")
index-file.names = ("index.html")
$HTTP["host"] == "subdomain.example.com" {
server.document-root = "/var/www/servers/subdomain.example.com"
}
# touch /etc/init.d/lighttpd # chmod a+rx /etc/init.d/lighttpd # chkconfig --add lighttpd # chkconfig lighttpd on
#!/bin/sh
#
# lighttpd Startup script for the lighttpd server
#
# chkconfig: - 85 15
# description: Lightning fast webserver with light system requirements
#
# processname: lighttpd
# config: /etc/lighttpd/lighttpd.conf
# config: /etc/sysconfig/lighttpd
# pidfile: /var/run/lighttpd.pid
#
# Note: pidfile is assumed to be created
# by lighttpd (config: server.pid-file).
# If not, uncomment 'pidof' line.
# Source function library
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/lighttpd ]; then
. /etc/sysconfig/lighttpd
fi
if [ -z "$LIGHTTPD_CONF_PATH" ]; then
LIGHTTPD_CONF_PATH="/etc/lighttpd/lighttpd.conf"
fi
prog="lighttpd"
lighttpd="/usr/local/sbin/lighttpd"
RETVAL=0
start() {
echo -n $"Starting $prog: "
daemon $lighttpd -f $LIGHTTPD_CONF_PATH
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc $lighttpd
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
return $RETVAL
}
reload() {
echo -n $"Reloading $prog: "
killproc $lighttpd -HUP
RETVAL=$?
echo
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
condrestart)
if [ -f /var/lock/subsys/$prog ]; then
stop
start
fi
;;
reload)
reload
;;
status)
status $lighttpd
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|reload|status}"
RETVAL=1
esac
exit $RETVAL
Certainly you can place the document root where you like, here is how I set it up for this particular config file.
# mkdir -p /var/www/servers/example.com # mkdir -p /var/www/servers/subdomain.example.com # echo "test successful" > /var/www/servers/example.com/index.html # echo "test successful subdomain.example.com" > /var/www/servers/subdomain.example.com/index.html
# /etc/init.d/lighttpd start
© 2011-2013 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

0 Comments
Add new comment