在LighttpdServer中设置VirtualHosts的方法-成都快上网建站

在LighttpdServer中设置VirtualHosts的方法

在Lighttpd Server中设置VirtualHosts的方法?这个问题可能是我们日常学习或工作经常见到的。希望通过这个问题能让你收获颇深。下面是小编给大家带来的参考内容,让我们一起来看看吧!

创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于成都做网站、网站建设、灌云网络推广、小程序开发、灌云网络营销、灌云企业策划、灌云品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联公司为所有大学生创业者提供灌云建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com

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中创建的页面上的正确内容。

感谢各位的阅读!看完上述内容,你们对在Lighttpd Server中设置VirtualHosts的方法大概了解了吗?希望文章内容对大家有所帮助。如果想了解更多相关文章内容,欢迎关注创新互联行业资讯频道。


网站栏目:在LighttpdServer中设置VirtualHosts的方法
文章转载:http://kswjz.com/article/jgjhhd.html
扫二维码与项目经理沟通

我们在微信上24小时期待你的声音

解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流