h?t?t?p?d??v?h?o?s?t?s?文件在apache中配置是非常重要的一個環節了,我們可以把所有目錄都配置到h?t?t?p?d??v?h?o?s?t?s?中,下面整理了一些例子,我們一起來看看.
實例一,Apache 配置localhost虛擬主機步驟
1,用記事本打開apache目錄下httpd文件(如:D:/wamp/bin/apache/apache2.2.8conf),找到如下模塊.
# Virtual hosts
#Include conf/extra/httpd-vhosts.conf
去掉前面的#,這樣就開啟了httpd-vhosts虛擬主機文件,這時候重啟wamp環境,無法打開localhost,需要在httpd- vhosts.conf配置一下.
2,用記事本打開httpd-vhosts文件,配置好localhost虛擬主機,參照httpd- vhosts文件中實例,修改成如下:
- <VirtualHost *:80>
- ServerAdmin webmaster@dummy-host.localhost
- DocumentRoot “D:wampwww”
- ServerName localhost
- ServerAlias localhost
- ErrorLog “logs/dummy-host.localhost-error.log”
- CustomLog “logs/dummy-host.localhost-access.log” common
- </VirtualHost>
- //開源代碼Vevb.com
修改配置如下:
DocumentRoot 修改為本地wamp環境下的www目錄(如:D:wampwww),ServerName改為localhost.
3,重啟Apache,發現localhost可以正常打開,配置localhost比較簡單.
實例二,Apache配置 www.49028c.com虛擬主機步驟
1,方法同上,復制配置代碼修改如下:
- <VirtualHost *:80>
- ServerAdmin test@biuuu.com
- DocumentRoot E:WebRootbiuuu
- ServerName www.49028c.com
- ErrorLog “logs/dummy-host2.localhost-error.log”
- CustomLog “logs/dummy-host2.localhost-access.log” common
- </VirtualHost>
2,打開host文件(C:/WINDOWS/system32/driversetchosts,增加一行代碼:
127.0.0.1 www.49028c.com
3,在瀏覽器中打開www.49028c.com,發現如下錯誤403 Forbidden錯誤
Forbidden,You don’t have permission to access / on this server.
分析:這主要是目錄訪問權限沒有設置,需要設置對目錄的訪問權.
4,打開httpd文件,找到 如下語句:
- <Directory />
- Options FollowSymLinks
- AllowOverride None
- Order deny,allow
- Deny from all
- </Directory>
復制以上代碼,并進行目錄修改,把/替換為E:WebRootbiuuu,修改virtualHost代碼如下:
- <VirtualHost *:80>
- ServerAdmin test@biuuu.com
- DocumentRoot E:WebRootbiuuu
- ServerName www.49028c.com
- ErrorLog “logs/dummy-host2.localhost-error.log”
- CustomLog “logs/dummy-host2.localhost-access.log” common
- <Directory E:WebRootbiuuu>
- Options FollowSymLinks
- AllowOverride None
- Order deny,allow
- Deny from all
- </Directory>
- </VirtualHost>
在瀏覽器中測試發現還是打不開,提示如上403 Forbidden錯誤,修改其中的Deny from all為allow from all.
5,重啟Apache,虛擬主機配置成功.
注意事項:
1,目錄路徑,如E:WebRootbiuuu
2,訪問權限,如上Deny from all修改為allow from all
3,host文件,配置虛擬域名host指向
4,httpd文件,打開Include conf/extra/httpd-vhosts.conf模塊
5,httpd-vhosts文件,配置虛擬主機
使用 Apache配置httpd-vhosts虛擬主機對于開發人員來說比較簡單,但卻非常重要,僅供參考.
D:wampalias 也可以這樣配置虛擬域名,和例二相同效果,代碼如下:
- <VirtualHost *:80>
- ServerName blog.cc
- ServerAlias blog.cc
- DocumentRoot “D:wampwwwblog”
- <Directory “D:wampwwwblog”>
- Options All FollowSymLinks IncludesNOEXEC Indexes
- DirectoryIndex index.html index.htm default.htm index.php default.php index.cgi default.cgi index.shtml index.aspx default.aspx
- AllowOverride All
- Order Deny,Allow
- Allow from all
- </Directory>
- </VirtualHost>
最后我們對php.ini做一下安全配置吧,代碼如下:
disable_functions = 在這里可以限制php函數
新聞熱點
疑難解答