apache虚拟主机

1.虚拟主机的定义

虚拟主机允许您从一个httpd服务器同时为多个网站提供服务。简单来讲就是基于名称的虚
拟主机其中多个主机名都指向同一个IP地址,但是Web服务器根据用于到达站点的主机名提供具有不
同内容的不同网站。例如,你访问www.qq.com和访问news.qq.com,访问的是不同的网页内容,但访问的IP地址其实是一样的。

在做虚拟主机之前,一定要关闭wifi 断开网络 要不然测试时会出404 Not Found ,这个错误让我损失了一下午时间,一定要切记

2.建立虚拟主机测试网页

[root@test ~]# mkdir /var/www/virtual/money.westos.com/html
[root@test ~]# mkdir /var/www/virtual/news.westos.com/html
[root@test ~]# echo "<h1> money.westos.com's page </h1>" > /var/www/virtual/money.westos.com/html/index.html   ##编写默认发布文件
[root@test ~]# echo "<h1> news.westos.com's page </h1>" > /var/www/virtual/news.westos.com/html/index.html    ##编写默认发布文件

3.配置apache子配置文件

[root@test ~]# vim /etc/httpd/conf.d/default.conf   ##建立默认子配置文件

<Virtualhost    default_:80>    ##虚拟机开启的端口
        DocumentRoot "/var/www/html"     ##虚拟主机的默认发布目录
        Customlog "logs/default.log" combined    ##虚拟主机日志
</Virtualhost>

[root@test ~]# vim /etc/httpd/conf.d/money.conf     ##建立子配置文件 使得指定域名money.westos.com的访问到指定默认发布目录中
<Virtualhost *:80>       ##虚拟机开启的端口
        ServerName "money.westos.com"   ##虚拟主机的名字
        DocumentRoot "/var/www/virtual/money.westos.com/html"     ##虚拟主机的默认发布目录
        Customlog "logs/money.log" combined      ##虚拟主机日志
</Virtualhost>
<Directory "/var/www/virtual/money.westos.com/html">   ##默认发布目录的访问授权
        Require all granted
</Directory>

[root@test ~]# cp -p /etc/httpd/conf.d/money.conf /etc/httpd/conf.d/news.conf  ##复制模板
[root@test ~]# vim /etc/httpd/conf.d/news.conf    ##建立子配置文件 使得指定域名news.westos.com的访问到指定默认发布目录中
<Virtualhost *:80>  ##虚拟机开启的端口
        ServerName "news.westos.com"  ##虚拟主机的名字
        DocumentRoot "/var/www/virtual/news.westos.com/html"  ##虚拟主机的默认发布目录
        Customlog "logs/news.log" combined     ##虚拟主机日志
</Virtualhost>
<Directory "/var/www/virtual/news.westos.com/html">     ##默认发布目录的访问授权
        Require all granted
</Directory>

4 测试

[root@foundation48 ~]# vim /etc/hosts
172.25.254.10 www.westos.com news.westos.com money.westos.com
这里写图片描述
这里写图片描述
这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值