• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Setup VirtualHosts in Lighttpd Server

Written by Rahul, Updated on March 23, 2014

VirtualHosting is an implementation of hosting multiple domains on single server. It enabled to utilize maximum resources of server and reduces cost. Now a days mostly all web servers supports virtualhosting environment. In our earlier article we describe to install Lighttpd server on CentOS/RHEL. This article will help you to setup VirtualHosts in Lighttpd server.

For example we are using following domains-

  1. site1.tecadmin.net
  2. site2.tecadmin.net

Step 1: Create Server Document Root

First create folders for both domains (if not exists)

# mkdir -p /sites/vhosts/site1.tecadmin.net/www
# mkdir -p /sites/vhosts/site2.tecadmin.net/www

For testing purpose we are creating an index.html file at both document roots

# echo "Welcome to Site1" > /sites/vhosts/site1.tecadmin.net/www/index.html
# echo "Welcome to Site2" > /sites/vhosts/site2.tecadmin.net/www/index.html

Step 2: Update Main Configuration File

Now edit Lighttpd main configuration file /etc/lighttpd/lighttpd.conf and enable to include virtualhosts files. Uncomment following line by removing starting # symbol.

include_shell "cat /etc/lighttpd/vhosts.d/*.conf"

Step 3: Create VirtualHost Configuration Files

Now start creating virutalhost configuration file for both domains or subdomains, First creating for site1.tecadmin.net

# vim /etc/lighttpd/vhosts.d/site1.tecadmin.net.conf
$HTTP["host"] == "site1.tecadmin.net" {

        server.document-root = "/sites/vhosts/site1.tecadmin.net/public"
        server.errorlog = "/var/log/lighttpd/site1.tecadmin.net.error.log"
        accesslog.filename = "/var/log/lighttpd/site1.tecadmin.net.access.log"
}

Now create configuration file for site2.tecadmin.net –

# vim /etc/lighttpd/vhosts.d/site2.tecadmin.net.conf
$HTTP["host"] == "site2.tecadmin.net" {

        server.document-root = "/sites/vhosts/site2.tecadmin.net/public"
        server.errorlog = "/var/log/lighttpd/site2.tecadmin.net.error.log"
        accesslog.filename = "/var/log/lighttpd/site2.tecadmin.net.access.log"
}

Step 4: Verify Configuration and Restart Lighttpd

After making all above configuration, first verify the syntax of all configuration file including main configuration file with

# lighttpd -t -f /etc/lighttpd/lighttpd.conf

Syntax OK

If you found that all syntax is ok, lets restart service

# service lighttpd restart

Now test your both domain in browser and check that you are getting correct content on pages as created in step 1. For more details about VirtualHosts in Lighttpd visit its official site.

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply Cancel reply

Popular Posts

  • How To Install Python 3.9 on Ubuntu 20.04 5
  • How To Install Python 3.9 on Ubuntu 18.04 0
  • How to Use AppImage on Linux (Beginner Guide) 2
  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy