1. 虚拟主机站点目录规划表:

域名 站点目录
www.etiantian.org /app/apache/htdocs/www
blog.etiantian.org /app/apache/htdocs/blog
bbs.etiantian.org /app/apache/htdocs/bbs

修改httpd.conf文件,找到下面两行(httpd.conf文件在apache安装目录下的conf目录里)
#Include conf/extra/httpd-vhosts.conf 《=把前面的#号去掉
#ServerName www.example.com:80 《=去掉前面的#号,并改成ServerName 127.0.0.1:80

2. 基于域名的配置

  1. 编辑 httpd-vhosts.conf文件,在末尾加上如下信息,修改好配置文件需要重启apache

vim /app/apache/conf/extra/httpd-vhosts.conf


ServerAdmin 1259018888@qq.com
DocumentRoot “/app/apache2.2.31/htdocs/www”
ServerName www.etiantian.org
ServerAlias etiantian.org
ErrorLog “logs/www-error_log”
CustomLog “logs/www-access_log” common

ServerAdmin 1259018888@qq.com
DocumentRoot “/app/apache2.2.31/htdocs/bbs”
ServerName bbs.etiantian.org
ErrorLog “logs/bbs-error_log”
CustomLog “logs/bbs-access_log” common

ServerAdmin 1259018888@qq.com
DocumentRoot “/app/apache2.2.31/htdocs/blog”
ServerName blog.etiantian.org
ErrorLog “logs/blog-error_log”
CustomLog “logs/blog-access_log” common

3. 创建测试文件

cd /app/apache/htdocs/
mkdir bbs www blog

echo “apache www” >www/index.html
echo “apache blog” >blog/index.html
echo “apache bbs” >bbs/index.html

4. 测试检查结果

做好相应的hosts文件解析后,就可以通过域名访问了
[root@web01 web]# curl www.etiantian.org
apache www
[root@web01 web]# curl bbs.etiantian.org
apache bbs
[root@web01 web]# curl blog.etiantian.org
apache blog