apache配置虛擬機的方式一共有三種方式,今天介紹如何在基于端口的情況下配置虛擬機。
第一步:將監聽端口添加到主配置文件:
[root@localhost conf]# vim /etc/httpd/conf/httpd.conf
在原有行Listen 80行的基礎上, 在添加一行
Listen 8080
第二步:將8080端口的虛擬配置添加好:
[root@localhost conf.d]# cat virtualhost.conf
<VirtualHost 192.168.137.200:80>
DocumentRoot "/var/www/test200"
ServerName www.test200.com
</VirtualHost>
<VirtualHost 192.168.137.201:80>
DocumentRoot "/var/www/test201"
ServerName www.test201.com
</VirtualHost>
#下面的內容是在上面的配置的基礎上添加的。
<VirtualHost 192.168.137.201:8080>
DocumentRoot "/var/www/test201-8080"
ServerName www.test201-8080.com
</VirtualHost>
[root@localhost conf.d]# cd /var/www/ #切換目錄
[root@localhost www]# mkdir test201-8080 #創建目錄
[root@localhost www]# echo "test201-8080" >>./test201-8080/index.html #創建主頁
第三步:檢測
[root@localhost www]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
[ OK ]
[root@localhost conf]# elinks -source 192.168.137.201:80
test201
[root@localhost conf]# elinks -source 192.168.137.201
test201
[root@localhost conf]# elinks -source 192.168.137.201:8080