在Lighttpd Server中设置VirtualHosts的方法

发布时间:2020-08-26 13:56:37 作者:小新
来源:亿速云 阅读:175

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

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的方法大概了解了吗?希望文章内容对大家有所帮助。如果想了解更多相关文章内容,欢迎关注亿速云行业资讯频道。

推荐阅读:
  1. 在SQL Server中重命名JSON密钥的方法
  2. 在Lighttpd Server中配置SSL的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

virtualhosts 中设置 st

上一篇:python库的调用方法

下一篇:用struts2实现简单的登录操作

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》