r3421555 发表于 2017-8-18 12:39:53

apache设置多个默认发布页面

最近学到apache,知道了怎样搭建服务器怎样设置一些参数从而达到不同效果,在生活中,我们会发现,比如腾讯,你进入www.qq.com 会发现里面还有音乐邮箱等,这些发布页面如果再新搭建一个服务器,将会特别费事。所以我们开始思考怎样设置多个默认发布页面
一:环境
服务器:

# hostnamectl
   Static hostname: n/a
Transient hostname: localhost.localdomain
         Icon name: computer-vm
         Chassis: vm
      Machine ID: 946cb0e817ea4adb916183df8c4fc817
         Boot ID: 8342d5606ee9481b9d347bce771c574a
    Virtualization: kvm
Operating System: Red Hat Enterprise Linux Server 7.0 (Maipo)
       CPE OS Name: cpe:/o:redhat:enterprise_linux:7.0:GA:server
            Kernel: Linux 3.10.0-123.el7.x86_64
      Architecture: x86_64

ip :172.25.254.120
二:准备工作
yum install -y httpd
systemctl start httpd
systemctl enable httpd
systemctl stop firewalld
三:搭建多个发布页面
1:新建发布目录和发布页面

# mkdir /var/www/zpy/news.zpy.com##新建发布目录
# vim /var/www/html/index.html    ##新建默认发布页面
# vim /var/www/zpy/news.zpy.com/index.html##新建发布页面
# cat /var/www/html/index.html
www.py.com
# cat /var/www/zpy/news.zpy.com/index.html
news.zpy.com
2:配置不同发布文件的发布目录
vim /etc/httpd/conf.d/default.conf

1
2
3
4
<Virtualhost _default_:80>          ##默认访问80端口
      DocumentRoot "/var/www/html"##默认发布目录
      CustomLog "logs/default.log" combined##日志
</Virtualhost>




# vim /etc/httpd/conf.d/news.conf



1
2
3
4
5
6
7
8
<Virtualhost *:80>          ##默认访问端口
      ServerName news.zpy.com   ##访问服务名称
      DocumentRoot "/var/www/zpy/news.zpy.com"##发布目录
      CustomLog "logs/news.log" combined##日志记录地点   
</Virtualhost>
<Directory "/var/www/zpy/news.zpy.com">    ##认证
      Require all granted##允许访问
</Directory>




# systemctl restart httpd   ##重启服务
四:测试
在客户端本地解析写入
# vim /etc/hosts

1
172.25.254.120www.zpy.com   music.zpy.com   news.zpy.com login.zpy.com




访问:
www.zpy.com   news.zpy.com



页: [1]
查看完整版本: apache设置多个默认发布页面