Rumah  >  Artikel  >  Operasi dan penyelenggaraan  >  如何在Lighttpd Server中设置VirtualHosts(虚拟主机)

如何在Lighttpd Server中设置VirtualHosts(虚拟主机)

不言
不言asal
2019-04-01 16:06:254176semak imbas

VirtualHosting是在单个服务器上托管多个域的一种实现。它能够利用服务器的最大资源并降低消耗现在,大多数Web服务器都支持虚拟主机环境。

如何在Lighttpd Server中设置VirtualHosts(虚拟主机)

在我们之前的文章中,我们介绍了在CentOS / RHEL上安装Lighttpd服务器。本篇文章将介绍关于在Lighttpd服务器中设置VirtualHosts。

例如,我们使用以下域名:

site1.php.cn

site2.php.cn

步骤1:创建服务器文档根目录

首先为两个域创建文件夹(如果不存在)

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

出于测试目的,我们在两个文档根目录中创建index.html文件

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

步骤2:更新主配置文件

现在编辑Lighttpd主配置文件/etc/lighttpd/lighttpd.conf并启用包含虚拟主机的文件。通过删除起始#符号取消对以下行的注释。

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

步骤3:创建VirtualHost配置文件

现在开始为两个域或子域创建virutalhost配置文件,首先为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"
}

现在为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"
}

步骤4:验证配置并重新启动lighttpd

首先验证所有配置文件的语法,包括主配置文件

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

Syntax OK

如果发现所有语法都正常,让我们重新启动服务。

# service lighttpd restart

完成后在浏览器中测试你的两个域,并检查是否获得了步骤1中创建的页面上的正确内容。

【相关推荐:Linux视频教程

Atas ialah kandungan terperinci 如何在Lighttpd Server中设置VirtualHosts(虚拟主机). Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn