WAMP下Apache配置httpd-vhosts虚拟主机多站点

开发环境:WAMP
  实例一,Apache配置localhost虚拟主机步骤
  1,用记事本打开apache目录下httpd文件(如:D:\wamp\bin\apache\apache2.2.8\conf),找到以下模块
  
  #Virtualhosts
  #Includeconf/extra/httpd-vhosts.conf
  去掉前面的#,这样就开启了httpd-vhosts虚拟主机文件。这时候重启wamp环境,没法打开localhost,须要在httpd-vhosts.conf配置一下。
  
  2,用记事本打开httpd-vhosts文件,配置好localhost虚拟主机,参照httpd-vhosts文件中实例,修改为以下:
  
  <VirtualHost*:80>
  ServerAdminwebmaster@dummy-host.localhost
  DocumentRoot”D:\wamp\www”
  ServerNamelocalhost
  ServerAliaslocalhost
  ErrorLog”logs/dummy-host.localhost-error.log”
  CustomLog”logs/dummy-host.localhost-access.log”common
  </VirtualHost>
  修改配置以下:
  DocumentRoot修改成本地wamp环境下的www目录(如:D:\wamp\www)
  ServerName改成localhost
  
  3,重启Apache,发现localhost能够正常打开,配置localhost比较简单。
  
  实例二,Apache配置test.biuuu.com虚拟主机步骤
  
  1,方法同上,复制配置代码修改以下:
  
  <VirtualHost*:80>
        ServerAdmintest@biuuu.com
  DocumentRootE:\WebRoot\biuuu
  ServerNametest.biuuu.com
  ErrorLog”logs/dummy-host2.localhost-error.log”
  CustomLog”logs/dummy-host2.localhost-access.log”common
  </VirtualHost>
  2,打开host文件(C:\WINDOWS\system32\drivers\etc\hosts),增长一行代码
  
  127.0.0.1test.biuuu.com
  3,在浏览器中打开test.biuuu.com,发现以下错误403Forbidden错误
  Forbidden
  Youdon’thavepermissiontoaccess/onthisserver.
  
  分析:这主要是目录访问权限没有设置,须要设置对目录的访问权!
  
  4,打开httpd文件,找到以下语句
  
  <Directory/>
  OptionsFollowSymLinks
  AllowOverrideNone
  Orderdeny,allow
  Denyfromall
  </Directory>
  复制以上代码,并进行目录修改,把/替换为E:\WebRoot\biuuu,修改virtualHost代码以下
  
  <VirtualHost*:80>
  ServerAdmintest@biuuu.com
  DocumentRootE:\WebRoot\biuuu
  ServerNametest.biuuu.com
  ErrorLog”logs/dummy-host2.localhost-error.log”
  CustomLog”logs/dummy-host2.localhost-access.log”common
  
  <DirectoryE:\WebRoot\biuuu>
  OptionsFollowSymLinks
  AllowOverrideNone
  Orderdeny,allow
  Denyfromall
  </Directory>
  
  </VirtualHost>
  在浏览器中测试发现仍是打不开,提示如上403Forbidden错误,修改其中的Denyfromall为allowfromall
  
  5,重启Apache,虚拟主机配置成功!
  
  注意事项
  1,目录路径,如E:\WebRoot\biuuu
  2,访问权限,如上Denyfromall修改成allowfromall
  3,host文件,配置虚拟域名host指向
  4,httpd文件,打开Includeconf/extra/httpd-vhosts.conf模块
  5,httpd-vhosts文件,配置虚拟主机
  
  使用Apache配置httpd-vhosts虚拟主机对于开发人员来讲比较简单,但却很是重要,仅供参考!web

相关文章
相关标签/搜索