Get the App
SLTechnology News&Howtos  ›  Servers  › 

The method of setting VirtualHosts in Lighttpd Server

Shulou Source: shulou.com Published: 2022-06-02 04:36:48 09月30日 Update

How to set VirtualHosts in Lighttpd Server? This problem may be often seen in our daily study or work. I hope you can gain a lot from this question. The following is the reference content that the editor brings to you, let's take a look at it!

VirtualHosting is an implementation that hosts multiple domains on a single server. It can take advantage of the maximum resources of the server and reduce consumption. Now, most Web servers support virtual host environments.

In our previous article, we introduced installing a Lighttpd server on CentOS / RHEL. This article will introduce you to setting up VirtualHosts in a Lighttpd server.

For example, we use the following domain name:

Site1.php.cn

Site2.php.cn

Step 1: create the server document root directory

First create a folder for the two domains (if they do not exist)

# mkdir-p / sites/vhosts/site1.php.cn/www# mkdir-p / sites/vhosts/site2.php.cn/www

For testing purposes, we created the index.html file in two document root directories

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

Step 2: update the main profile

Now edit the Lighttpd main configuration file / etc/lighttpd/lighttpd.conf and enable the file that contains the virtual host. Uncomment the following line by removing the starting # symbol.

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

Step 3: create a VirtualHost profile

Now start creating virutalhost profiles for two domains or subdomains, first for site1.php.cn

# vim / etc/lighttpd/vhosts.d/site1.php.cn.conf$HTTP ["host"] = = "site1.php.cn" {server.document-root = "/ sites/vhosts/site1.php.cn/public" server.errorlog = "/ var/log/lighttpd/site1.php.cn.error.log" accesslog.filename = "/ var/log/lighttpd/site1.php.cn.access.log"}

Now create a configuration file for site2.php.cn

# vim / etc/lighttpd/vhosts.d/site2.php.cn.conf$HTTP ["host"] = = "site2.php.cn" {server.document-root = "/ sites/vhosts/site2.php.cn/public" server.errorlog = "/ var/log/lighttpd/site2.php.cn.error.log" accesslog.filename = "/ var/log/lighttpd/site2.php.cn.access.log"}

Step 4: verify the configuration and restart lighttpd

First verify the syntax of all configuration files, including the main configuration file

# lighttpd-t-f / etc/lighttpd/lighttpd.confSyntax OK

If you find that all the syntax is normal, let's restart the service.

# service lighttpd restart

When you are done, test your two fields in the browser and check to see if you have obtained the correct content on the page created in step 1.

Thank you for reading! After reading the above, do you have a general idea of how to set up VirtualHosts in Lighttpd Server? I hope the content of the article will be helpful to all of you. If you want to know more about the relevant articles, you are welcome to follow the industry information channel.

Tags: File configuration service server content step two article central method host document root virtual host syntax problem creation testing verification maximum Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Linux MySQL MariaDB Redmi