1.取消httpd.conf中以下行的注释
Include conf/extra/httpd-vhosts.conf
2.增加虚拟主机的目录,代表该目录作为一个网站的虚拟目录,配置权限,允许访问:
<Directory "D:jowebh_CN"> Options FollowSymLinks AllowOverride None Order deny,allow allow from all </Directory>
3.配置【/extra/httpd-vhosts.conf】增加虚拟主机配置,这里使用的是固定IP固定端口以不同的域名来访问的虚拟主机方式:
以下为片段:
Listen 80 #市院 NameVirtualHost *:80 <VirtualHost *:80> ServerName www.xx.xx.gov.cn DocumentRoot D:/bjoweb/Zh_CN/sj DirectoryIndex index.html ErrorLog logs/www.bj.jjc.gov.cn-error_log.log CustomLog logs/www.bj.jjc.gov.cn-access_log.log common </VirtualHost> #市院 NameVirtualHost * <VirtualHost *:80> ServerName www.xx.gov.cn DocumentRoot D:/xx/Zh_CN/sj DirectoryIndex index.html ErrorLog logs/www.xx.gov.cn-error_log.log CustomLog logs/www.xx.gov.cn-access_log.log common </VirtualHost>
代表在80端口上监听,对于不同域名的访问定向到不同的目录下面。。
基于ip地址的虚拟主机 Listen 80 <VirtualHost 172.20.30.40> DocumentRoot /home/httpd/html1 ServerName www.ok1.com ErrorLog /usr/local/apache/logs/error1_log CustomLog /usr/local/apache/logs/access1_log combined </VirtualHost> <VirtualHost 172.20.30.50> DocumentRoot /home/httpd/html2 ServerName www.ok2.com ErrorLog /usr/local/apache/logs/error2_log CustomLog /usr/local/apache/logs/access2_log combined </VirtualHost>