1、修改Apache主配置文件
[root@localhost ~]# vim /usr/local/apache2/conf/httpd.confInclude conf/extra/httpd-vhosts.conf
2、修改虚拟主机文件
# ServerAdmin webmaster@dummy-host.example.com[root@localhost two.com]# vim /usr/local/apache2/conf/extra/httpd-vhosts.conf DocumentRoot "/usr/local/apache2/htdocs/one.com" //网页文档配置路径 ServerName www.one.com //虚拟主机名称 ServerAlias www.1.com //虚拟主机别名 DocumentRoot "/usr/local/apache2/htdocs/two.com" ServerName www.two.com ServerAlias www.1.com
3、创建网页配置文件
[root@localhost htdocs]# mkdir one.com two.com[root@localhost htdocs]# cd one.com[root@localhost one.com]# echo "This is first page" >index.html[root@localhost htdocs]# cd two.com/[root@localhost two.com]# echo "This is second page" >index.html
4、测试
[root@localhost two.com]# /usr/local/apache2/bin/apachectl restart[root@localhost two.com]# curl www.one.comThis is first page[root@localhost two.com]# curl www.two.comThis is second page