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