怎样配置Apache虚拟主机
1、安装Apache软件包
yum -y install httpd
(这里只实现Apache的虚拟主机功能,LAMP架构还需要安装php和mysqld-server等软件包)

2、打开Apache的主配置文件
#vim /etc/httpd/conf/httpd.conf
取消“#NameVirtualHost *:8”行首#注释
NameVirtualHost *:8
添加
<VirtualHost *:80>
ServerAdmin webmaster@example.com
DocumentRoot /var/www/html/web1
ServerName web1.example.com
ErrorLog logs/web1.example.com-error_log
CustomLog logs/web1.example.com-access_log common
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@example.com
DocumentRoot /var/www/html/web2
ServerName web2.example.com
ErrorLog logs/web2.example.com-error_log
CustomLog logs/web2.example.com-access_log common
</VirtualHost>
ServerAdmin是网站管理员的邮箱
DocumentRoot是网站存放的路径
ServerName是你的网站域名
ErrorLog、CustomLog是日志文件
添加多个网站的时候DocumentRoot和ServerName必须不同


3、启动Apache服务
/etc/init.d/httpd start
chkconfig httpd on
4、在防火墙中添加80端口
#grep 80 /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

5、在域名管理后台添加域名解析记录,然后访问域名就能跳转到对应的网站上面了。