關於wamp5中(apache)設置虛擬主機

找了不少文章,可是不少對於最新的apache都已通過時沒法生效了。apache

http://blog.csdn.net/yuluo727282752/article/details/6944359 這篇文章寫得很是好,記錄下來,下面爲全文引用。瀏覽器

 

完成一個項目,總要進行一些測試,可是在本身本上測試或許有一些本身想不到的BUG出現,因而配置一個虛擬主機能夠爲本身更方便的解決BUG,也能夠方便演示時你們測試ide

如下是我在網上尋到的一些方法,分享給你們測試

 

開發環境:WAMP this

 

 實例一,Apaceh配置localhost虛擬主機步驟.net

 

  1,用記事本打開apache目錄下httpd文件(如:D:\wamp\bin\apache\apache2.2.8\conf),找到以下模塊server

  # Virtual hosts#Include conf/extra/httpd-vhosts.conf往掉#Include conf/extra/httpd-vhosts.conf前面的#,這樣就開啓了httpd-vhosts虛擬主機文件。這時候重啓wamp環境,沒法打開localhost,須要在httpd-vhosts.conf配置一下。個人wamp安裝在D盤blog

 

  2,用記事本打開httpd-vhosts文件,配置好localhost虛擬主機,參照httpd-vhosts文件中實例,修改爲以下:開發

  <VirtualHost *:80>ServerAdmin DocumentRoot "D:\wamp\www"ServerName localhostServerAlias localhostErrorLog "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比較簡單。

 

實例二,Apaceh配置test.biuuu.com虛擬主機步驟

 

  1,方法同上,複製配置代碼修改以下:

  <VirtualHost *:80>

    ServerAdmin

    DocumentRoot "d:/wamp/www/magento"

    ServerName www.jiangpeng.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.1 www.jiangpeng.com3,在瀏覽器中打開www.jiangpeng.com,發現以下錯誤403 Forbidden錯誤

      Forbidden

      You don't have permission to access / on this server.

    分析:這主要是目錄訪問權限沒有設置,須要設置對目錄的訪問權!

 

  4,打開httpd文件,找到以下語句

  <Directory />Options FollowSymLinksAllowOverride NoneOrder deny,allowDeny from all</Directory>

  複製以上代碼,並進行目錄修改,把/替換爲d:/wamp/www/magento(項目代碼根目錄),修改virtualHost代碼以下

  <VirtualHost *:80>

    ServerAdmin "d:/wamp/www/magento"

    ServerName www.jiangpeng.com

    ErrorLog "logs/dummy-host2.localhost-error.log"

    CustomLog "logs/dummy-host2.localhost-access.log" common

  </VirtualHost>

      <Directory "d:/wamp/www/magento">

    Options Indexes FollowSymLinks

    AllowOverride all

    Order Allow,Deny

    Allow from all

  </Directory>

  在瀏覽器中測試發現仍是打不開,提示如上403 Forbidden錯誤,修改其中的Deny from all爲allow from all

 

  5,重啓Apache,虛擬主機配置成功!

 

  留意事項

  1,目錄路徑,如d:/wamp/www/magento

  2,訪問權限,如上Deny from all修改成allow from all

  3,host文件,配置虛擬域名host指向

  4,httpd文件,打開Include conf/extra/httpd-vhosts.conf模塊

  5,httpd-vhosts文件,配置虛擬主機

相關文章
相關標籤/搜索