本地apache虚拟主机的配置

第一步:在 C:\WINDOWS\system32\drivers\etc 下找到 hosts  文件 ,打开并且在最后加上
127.0.0.1          localhost
127.0.0.1          uc.521-wf.com
127.0.0.1          uch.521-wf.com
第二步:在apache 的配置文件 httpd.conf 的最后加上如下的代码:
  1. NameVirtualHost 127.0.0.1
  2. <VirtualHost 127.0.0.1:80>
  3. ServerAdmin admin@521-wf.com
  4. DocumentRoot c:/wamp/www/
  5. ServerName localhost
  6. </VirtualHost>
  7.  
  8. <VirtualHost 127.0.0.1:80>
  9. ServerAdmin admin@521-wf.com
  10. DocumentRoot c:/wamp/www/uc/
  11. ServerName uc.521-wf.com
  12. </VirtualHost>
  13.  
  14. <VirtualHost 127.0.0.1:80>
  15. ServerAdmin admin@521-wf.com
  16. DocumentRoot c:/wamp/www/uch/
  17. ServerName uch.521-wf.com
  18. </VirtualHost>
但是这是核心的代码,不是固定的写法:
     ServerAdmin   你的邮件地址(不过可以随便写,这也只不过是虚拟环境而已)
      DocumentRoot  这是你项目的路径
      ServerName    这是你的虚拟域名
有时候你把上面的127.0.0.1 换为 * 也可以。但是有时候不行。我建议还是加上。
我习惯于使用 wamp  所以我并没有加在配置文件的最后面,而是加在了以下两行代码之前:
Include "c:/wamp/apache2/conf/alias/phpmyadmin.conf"
Include "c:/wamp/apache2/conf/alias/sqlitemanager.conf"
当然如果你的操作系统装在了d盘,或者是其他盘,那就看着办吧! 这个配置我在学校里面配置我好多次,不能说倒背如流,但是可以说是滚光烂熟了吧。但是到了公司,两个多月不用了,突然想装一下uchome ,配置了半天,老是出错 。所以 还是写在这儿,以防以后再忘了。  <<<<<<<<<<<<<<<<<<<<<<<<<<补充,还可以使用以下这种方式,更安全
  1. <VirtualHost *:80>
  2. DocumentRoot "D:/wamp/www/framework/webroot"
  3. ServerName star
  4. #ServerAlias *.shop.com.cn
  5. ErrorLog "logs/starland.ifensi-error.log"
  6. CustomLog "logs/make.openqee.com.cn.log" common
  7. <Directory "D:/wamp/www/framework">
  8. Options FollowSymLinks
  9. AllowOverride All
  10. Order deny,allow
  11. allow from all
  12. DirectoryIndex index.html index.php
  13. </Directory>
  14. </VirtualHost>
24
Feb 2008
AUTHOR WiFeng
CATEGORY Web
COMMENTS 2 Comments