Lighttpd Configure Subdomain

in Categories , , last updated March 18, 2011

I‘ve main domain configured at and I’d like to use with different files. How do I add subdomain support with Lighttpd web server under UNIX or Linux operating systems?

You can setup lighttpd server as follows:

  • will use /home/lighttpd/ as document root
  • will use /home/lighttpd/ as document root

Both domain can point to the same ip address or different ip address. Edit lighttpd.conf, enter:
# vi /etc/lighttpd/lighttpd.conf
Update / edit as follows:

server.modules              = (
server.errorlog            = "/var/log/lighttpd/error.log"
accesslog.filename         = "/var/log/lighttpd/access.log"
index-file.names            = ( "index.php", "index.html", "index.htm", "default.htm" )
server.tag                 = "lighttpd"
server.document-root = "/home/lighttpd/"
server.username = "lighttpd"
server.groupname = "lighttpd"
server.port = "80"
server.bind = ""  
###### Subdomain settings ##############
$HTTP["host"]  == ""{
        server.document-root = "/home/lighttpd/"
        accesslog.filename         = "/var/log/lighttpd/"

Save and close the file. Create required directories for subdomain:
# mkdir -p /home/lighttpd/
# mkdir /var/log/lighttpd/

Reload or restart the lighttpd server:
# /etc/init.d/lighttpd reload
You can now upload all files at /home/lighttpd/ for

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

Share this on (or read 2 comments/add one below):

2 comment

  1. I’ve been struggeling to get this to work with a subdomain on an other server.
    Can you give an example where it routes the subdomain to an other server while using only one public IP.
    To clarify a bit:
    public IP goes to and blog.mydomain.
    server 1 hosts (internal ip
    server 2 hosts (internal ip
    server 1 is dmz (so lands you on server 1)

    Have a question? Post it on our forum!