Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Web Servers»Lighttpd»How to Setup VirtualHosts in Lighttpd Server

    How to Setup VirtualHosts in Lighttpd Server

    RahulBy RahulMarch 23, 20142 Mins Read

    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.

    lighttpd virtualhost web-server
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleCHECK_NRPE: Error – Could not complete SSL handshake.
    Next Article How to Configure SSL in Lighttpd Server

    Related Posts

    How To Install Linux, Nginx, MySQL, & PHP (LEMP Stack) on Ubuntu 22.04

    Updated:April 7, 20227 Mins Read

    How to Increase Request Timeout in NGINX

    Updated:January 13, 20222 Mins Read

    How To Disable HTTP Methods in Apache

    Updated:December 31, 20212 Mins Read

    How to Install and Secure Apache on Debian11

    6 Mins Read

    How To Enable Brotli Compression in Apache

    2 Mins Read

    How to Install Tomcat 10 on Debian 10

    Updated:February 18, 20225 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Import GPG Keys on Ubuntu & Debian (without apt-key)
    • How To Install Google Chrome On macOS
    • How to Install Minecraft on Ubuntu 22.04 & 20.04
    • Running a Cron job every Sunday (Weekly)
    • Running Multiple Commands At Once in Linux
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.