Apaceh配置httpd-vhosts虚拟主机
經(jīng)常使用Apache虛擬主機進行開發(fā)和測試,但每次需要配置虛擬主機時都習慣性的ctrl+c和ctrl+v,這次由于重裝系統(tǒng),需要配置一個新的PHP開發(fā)環(huán)境虛擬主機,于是總結(jié)一下Apaceh配置httpd-vhosts虛擬主機使用方法和步驟,便于查找和使用。
開發(fā)環(huán)境:WAMP
網(wǎng)址:http://www.wampserver.com/en/
實例一,Apaceh配置localhost虛擬主機步驟
1,用記事本打開apache目錄下httpd文件(如:D:\wamp\bin\apache\apache2.2.8\conf),找到如下模塊
去掉前面的#,這樣就開啟了httpd-vhosts虛擬主機文件。這時候重啟wamp環(huán)境,無法打開localhost,需要在httpd-vhosts.conf配置一下。
2,用記事本打開httpd-vhosts文件,配置好localhost虛擬主機,參照httpd-vhosts文件中實例,修改成如下:
<VirtualHost *:80> ServerAdmin webmaster@dummy-host.localhost DocumentRoot "D:\wamp\www" ServerName localhost ServerAlias localhost ErrorLog "logs/dummy-host.localhost-error.log" CustomLog "logs/dummy-host.localhost-access.log" common </VirtualHost>修改配置如下:
DocumentRoot 修改為本地wamp環(huán)境下的www目錄(如:D:\wamp\www)
ServerName改為localhost
3,重啟Apache,發(fā)現(xiàn)localhost可以正常打開,配置localhost比較簡單。
實例二,Apaceh配置test.biuuu.com虛擬主機步驟
1,方法同上,復制配置代碼修改如下:
<VirtualHost *:80> ServerAdmin test@biuuu.com DocumentRoot E:\WebRoot\biuuu ServerName test.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.1 test.biuuu.com3,在瀏覽器中打開test.biuuu.com,發(fā)現(xiàn)如下錯誤403 Forbidden錯誤
Forbidden
You don’t have permission to access / on this server.
分析:這主要是目錄訪問權(quán)限沒有設置,需要設置對目錄的訪問權(quán)!
4,打開httpd文件,找到如下語句
<Directory /> Options FollowSymLinks AllowOverride None Order deny,allow Deny from all </Directory>復制以上代碼,并進行目錄修改,把/替換為E:\WebRoot\biuuu,修改virtualHost代碼如下
<VirtualHost *:80> ServerAdmin test@biuuu.com DocumentRoot E:\WebRoot\biuuu ServerName test.biuuu.com ErrorLog "logs/dummy-host2.localhost-error.log" CustomLog "logs/dummy-host2.localhost-access.log" common <Directory E:\WebRoot\biuuu> Options FollowSymLinks AllowOverride None Order deny,allow Deny from all </Directory> </VirtualHost>在瀏覽器中測試發(fā)現(xiàn)還是打不開,提示如上403 Forbidden錯誤,修改其中的Deny from all為allow from all
5,重啟Apache,虛擬主機配置成功!
注意事項
1,目錄路徑,如E:\WebRoot\biuuu
2,訪問權(quán)限,如上Deny from all修改為allow from all
3,host文件,配置虛擬域名host指向
4,httpd文件,打開Include conf/extra/httpd-vhosts.conf模塊
5,httpd-vhosts文件,配置虛擬主機
使用Apaceh配置httpd-vhosts虛擬主機對于開發(fā)人員來說比較簡單,但卻非常重要,僅供參考!
參考資料:
http://httpd.apache.org/docs/2.2/vhosts/
http://httpd.apache.org/docs/2.0/vhosts/examples.html
原創(chuàng)文章如轉(zhuǎn)載,請注明:轉(zhuǎn)載自 必優(yōu)博客 http://www.biuuu.com/
顧銀鑫 注:如發(fā)生Fatal error: Allowed memory size of 8388608 bytes exhausted錯誤
修改php.ini設置memory_limit = 12M(默認8M)
或只需要在你的程序頭部加入: ini_set(“memory_limit”,”12M”);
總結(jié)
以上是生活随笔為你收集整理的Apaceh配置httpd-vhosts虚拟主机的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: thymeleaf 的 th:oncli
- 下一篇: redirect_uri 域名与后配置不