Lighttpd is a very light web server software that takes very few resources from your server, but also has fewer capabilities. When a website is serving both lots of images, javascripts, cascading style sheets(static content) and dynamic scripts (ASP, PHP, JSP or more), it is not wise to let apache serve both static and dynamic content. That is why, lighttpd can run besides apache on another port and serve requests for the static content of your website.
How to tell apache to redirect requests for static content to lighttpd (on another port, other than 80) is not the point of this tutorial.
The point is that the virtual host for the specific website/subdomain must be declared also in lighttpd configuration file, not only in apache's config file (httpd.conf).
How to create virtual hosts for Lighttpd
Use your favourite editor to open /etc/lighttpd/lighttpd.conf file (on Linux) or /usr/local/etc/lighttpd.conf (on FreeBSD) and, preferably at the bottom, add the following line (replace with what suits your needs the text in italic):
www.domain.ro is the domain for which you're declaring the virtual host and /home/www/domain.ro/public_html is the home directory for this domain where the static content resides (should be the same home directory declared in Apache's virtual host for this domain).
Now, in order for lighttpd to serve this domain, we must restart lighttpd. Here's how to do it on both Linux and FreeBSD:
Restarting lighttpd on Linux:
$ /etc/init.d/lighttpd restart * Stopping lighttpd ... [ ok ] * Starting lighttpd ... [ ok ] ================OR================ $ service lighttpd restart * Stopping lighttpd ... [ ok ] * Starting lighttpd ... [ ok ]
Restarting lighttpd on FreeBSD:
$ /usr/local/etc/rc.d/lighttpd restart
Now to test lighttpd configuration (we presume that apache's configuration is ok and requests for static content are redirected to http://127.0.0.1:xx, xx being the port on which lighttpd is listening) open your browser go to www.domain.ro:xx (xx is lighttpd's port).
If you see something it means it works. What you see depends on what's in the domain's home dir. Lighttpd meight not recognize dynamic content. Also make sure there are reading permissions for that directory and files (and so on..).
Designed and developed by Andrei Manescu. Optimized for Mozilla Firefox.
Copyright 2007 Andrei Manescu
All trademarks and copyrights on this page are owned by their respective owners. Comments are owned by those who posted them.