≡ Menu

Lighttpd Configure Subdomain

I‘ve main domain configured at http://example.com and I’d like to use http://support.example.com 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:

  • example.com will use /home/lighttpd/example.com/http as document root
  • support.example.com will use /home/lighttpd/support.example.com/http 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/example.com/http"
server.username = "lighttpd"
server.groupname = "lighttpd"
server.port = "80"
server.bind = ""  
###### Subdomain settings ##############
$HTTP["host"]  == "support.example.com"{
        server.document-root = "/home/lighttpd/support.example.com/http"
        accesslog.filename         = "/var/log/lighttpd/support.example.com/access.log"

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

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

Share this tutorial on:

Like this? Follow us on Twitter OR support us by using Patreon

{ 2 comments… add one }
  • dootzky May 27, 2014, 4:23 pm

    thank you! :)

    it worked! :D even 3 years later! ^_^

  • ivo November 8, 2015, 8:06 am

    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 mydomain.com and blog.mydomain.
    server 1 hosts mydomain.com (internal ip
    server 2 hosts blog.mydomain.com (internal ip
    server 1 is dmz (so mydomain.com lands you on server 1)

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , , , , , , , , , ,