1. 程式人生 > >centos7 搭建WEB伺服器

centos7 搭建WEB伺服器

centos7 搭建WEB伺服器

2017年09月17日 09:44:50  閱讀數:18321 標籤: centosapacheweb伺服器  個人分類: centos伺服器簡單配置  

步驟1:安裝Apache服務。

[[email protected] ~]# yum install -y httpd
  • 1

步驟2:啟動Apache服務。

[[email protected] ~]# systemctl start httpd.service 
  • 1

步驟3:分別建立“/var/www/web1”和“/var/www/web2”兩個主目錄和預設檔案。

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

步驟4:在/etc/httpd/conf/httpd.conf檔案中,設定基於域名的虛擬主機,配置內容如下。

[[email protected] ~]# 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的域名解析關係。

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

步驟6:重啟apache服務和DNS服務。

[[email protected] ~]# systemctl  restart httpd
[[email protected] ~]# systemctl restart named 
  • 1
  • 2

步驟7:測試Web伺服器。在一臺使用Windows 7作業系統的PC機上,訪問web1.text.com和web2.text.com,如下圖所示。