apache的虚拟主机

含义:

不同域名访问不同的页面

配置步骤:
1.vim /etc/hosts  ##编辑本地解析
    172.25.254.100    music.westos.com   news.westos.com
2.mkdir /var/www/virtual/news/html -p ##建立news发布目录
3.vim /var/www/virtual/news/html/index.html  ##编辑news发布文件
    <h1>new's page</h1>
4.mkdir /var/www/virtual/music/html -p ##建立music发布目录
5.vim /var/www/virtual/music/html/index.html ##编辑music发布文件
    </h1>music's page</h1>
6.cd /etc/httpd/conf.d/ ##切换到子配置目录
7.vim a_default.conf ##编辑默认访问文件,没有声明的都访问这个文件,默认虚拟主机
    <Virtualhost _default_:80> ##默认端口为80
        DocumentRoot /var/www/html ##默认访问此目录,默认的意思是没有声明
        CustomLog  logs/default.log combined ##logs表示/etc/httpd/logs  combined表示混合型日志。
    </Virtualhost>

8.vim news.conf  ##指定名称的虚拟主机
    <Virtualhost *:80> ##默认端口为80
            ServerName news.westos.com ##特殊指定就访问特殊指定页面
            DocumentRoot /var/www/virtual/news/html
        CustomLog  logs/news.log combined
    </Virtualhost>
    <Directory "/var/www/virtual/news/html"> ##授权
        Require all granted
    </Directory>

9.vim music.conf ##指定名称的虚拟主机
    <Virtualhost *:80> ##默认端口为80
            ServerName music.westos.com ##特殊指定就访问特殊指定的页面
            DocumentRoot /var/www/virtual/music/html
            CustomLog  logs/music.log combined
    </Virtualhost>
    <Directory "/var/www/virtual/music/html">
        Require all granted
    </Directory>

测试:

在浏览器上面输入
news.westos.com
music.westos.com
结果:不同域名显示不同页面

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值