centos7 搭建WEB服务器

centos7 搭建WEB服务器

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_26938637/article/details/78008427

步骤1:安装Apache服务。

[root@192 ~]# yum install -y httpd
  • 1

步骤2:启动Apache服务。

[root@192 ~]# systemctl start httpd.service 
  • 1

步骤3:分别创建“/var/www/web1”和“/var/www/web2”两个主目录和默认文件。

[root@192 ~]# cd /var/www
[root@192 www]# mkdir web1 web2
[root@192 www]# echo "this is web1" > web1/index.html
[root@192 www]# echo "this is web2" > web2/index.html
  • 1
  • 2
  • 3
  • 4

步骤4:在/etc/httpd/conf/httpd.conf文件中,设置基于域名的虚拟主机,配置内容如下。

[root@192 ~]# vim /etc/httpd/conf/httpd.conf
NameVirtualHost 192.168.0.111:80
<VirtualHost 192.168.0.111:80>
DocumentRoot /var/www/web1
ServerName web1.text.com
</VirtualHost>

<VirtualHost 192.168.0.111:80>
DocumentRoot /var/www/web2
ServerName web2.text.com
</VirtualHost>   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

步骤5:在/var/named/text.com.zone文件中,添加web1.text.com和web2.text.com的域名解析关系。

[root@192 ~]# vim /var/named/text.com.zone
web1    A       192.168.0.111
web2    A       192.168.0.111
  • 1
  • 2
  • 3

步骤6:重启apache服务和DNS服务。

[root@192 ~]# systemctl  restart httpd
[root@192 ~]# systemctl restart named 
  • 1
  • 2

步骤7:测试Web服务器。在一台使用Windows 7操作系统的PC机上,访问web1.text.com和web2.text.com,如下图所示。

猜你喜欢

转载自www.cnblogs.com/westsoft/p/9912519.html