通过hosts域名映射
127.0.0.1 www.moban.com
NameVirtualHost *:80 #配置 www.moban.com 虚拟主机 <VirtualHost *:80> #绑定域名 ServerName www.moban.com #网站根目录 DocumentRoot "D:WWWmoban" #网站默认首页文件 DirectoryIndex index.html index.php #网站目录访问权限 <Directory "D:WWWmoban"> Options Indexes FollowSymLinks #允许网站空间目录的分布式配置文件.htaccess #对虚拟主机的权限进行覆盖 AllowOverride All Order Deny,Allow Allow from All </Directory> </VirtualHost>
NameVirtualHost *:80 <VirtualHost *:80> ServerName www.test.com.cn DocumentRoot "D:xampphtdocswwwapiPublic" DirectoryIndex index.html index.php </VirtualHost> NameVirtualHost *:80 <VirtualHost *:80> ServerName www.666.com DocumentRoot "D:xampphtdocs666" DirectoryIndex index.html index.php </VirtualHost> NameVirtualHost *:80 <VirtualHost *:80> ServerName www.888.com DocumentRoot "D:xampphtdocs888" DirectoryIndex index.html index.php </VirtualHost>
通过ip
//可能会导致apache启动过慢
<VirtualHost 127.0.0.2:80> DocumentRoot "D:WWW est_ip" DirectoryIndex index.html index.php <Directory "D:WWW est_ip"> Options Indexes FollowSymLinks AllowOverride All Order Deny,Allow Allow from All #Require all granted </Directory> </VirtualHost>
通过相同ip不同端口配置
<VirtualHost 192.168.1.102:80> DocumentRoot "D:WWW est_ip" DirectoryIndex index.html index.php <Directory "D:WWW est_ip"> Options Indexes FollowSymLinks AllowOverride All Order Deny,Allow Allow from All #Require all granted </Directory> </VirtualHost> <VirtualHost 192.168.1.102:8080> DocumentRoot "D:WWWmoban" DirectoryIndex index.html index.php <Directory "D:WWWmoban"> Options Indexes FollowSymLinks AllowOverride All Order Deny,Allow Allow from All #Require all granted </Directory> </VirtualHost>
默认是没有开启其他端口的
如果出现拒绝访问则需要改httpd.conf文件
DocumentRoot "D:phpStudyWWW" <Directory /> Options +Indexes +FollowSymLinks +ExecCGI AllowOverride All Order allow,deny Allow from all Require all granted </Directory>
也有可能是vhost.conf中
Options FollowSymLinks ExecCGI //将 Options +Indexes +FollowSymLinks +ExecCGI //改为
phpstudy 中
Options -Indexes -FollowSymLinks +ExecCGI //将
Options +Indexes +FollowSymLinks +ExecCGI //改为
#apache加载php模块 LoadModule php5_module "C:wampphpphp5apache2_2.dll" AddType application/x-httpd-php .php PHPIniDir "C:wampphp"