这里介绍基于主机名的配置方法
环境目录:
- 修改hosts文件
IP地址 www.wscon.cn www.wsczx.com
- 修改httpd.conf文件
修改httpd.conf文件 在文件最后添加 Include vhost-conf.d/*.conf
或者使用命令
echo "Include vhost-conf.d/*.conf" >> conf/httpd.conf
- 修改httpd-vhosts.conf文件
//配置虚拟机主机
#cd /etc/httpd/
# mkdir vhost-conf.d
# vi /etc/httpd/vhost-conf.d/vhost-name.conf
//添加如下内容
<VirtualHost *:80>
ServerName wscon.cn
ServerAlias wscon.cn www.wscon.cn
DocumentRoot /var/www/html/site1
DirectoryIndex index.html index.php
</VirtualHost>
<Directory "/var/www/html/site1/">
Options Includes -Indexes
AllowOverride All
Order Deny,Allow
Allow from All
</Directory>
<VirtualHost *:80>
ServerName wsczx.com
ServerAlias wsczx.com www.wsczx.com
DocumentRoot /var/www/html/site2/
DirectoryIndex index.html index.php
</VirtualHost>
<Directory "/var/www/html/site2/m~@~>
Options Includes -Indexes
AllowOverride All
Order Deny,Allow
Allow from All
</Directory>
<VirtualHost *:80>
ServerName test.wsczx.com
# ServerAlias wsczx.com www.wsczx.com
DocumentRoot /var/www/html/site3/
DirectoryIndex index.html index.php
</VirtualHost>
<Directory "/var/www/html/site3/m~@~>
Options Includes -Indexes
AllowOverride All
Order Deny,Allow
Allow from All
</Directory>
虚拟主机配置到此结束;在对应的目录下新建html页面测试即可;