禁止訪問Apache目錄(2011-01-23 14:53:14)

來源:互聯網
上載者:User

標籤:localhost   運行環境   php網站   伺服器   設定檔   

   在PHP網站開發中,基於WEB伺服器和PHP網站程式碼的安全考慮,我們需要對相關的目錄或者檔案存取權限進行控制,以防止意外情況的發生,那麼我們如何來實現這種功能呢?我們可以通過Apache來實現禁止目錄訪問(禁止遊覽列出的目錄或檔案清單)、禁止或允許IP與網域名稱訪問目錄的功能。在Apache中配置禁止目錄訪問,即禁止遊覽列出的目錄/檔案清單的方法

  訪問網站目錄時Apache預設配置為可列出目錄/檔案清單,即當你訪問http://localhost時會列出相關的目錄和檔案清單,我們可以通過修改Apache設定檔httpd.conf來實現禁止列出目錄/檔案清單,方法如下:

1、開啟apache設定檔httpd.conf

2、找到


<Directory />

Options Indexes

AllowOverride None
Order allow,deny
Allow from all
</Directory>

    只需要修改Options Indexes為Options None即可,註:根據PHP運行環境安裝包的不同,Options Indexes也有可能是Options Indexes FollowSymLinks,一併改為Options None即可。

    還需注意的事:如果是自己重新設定了DocumentRoot,例如以下:修改的地方也就不同了

<Directory "D:/Apache2/webpage">

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# 
Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn‘t give it to you.
#
# The Options directive is both complicated and important. 
 Please see
# 
http://httpd.apache.org/docs/2.0/mod/core.html#options
# for more information.
#
 
  # Options Indexes FollowSymLinks
 
  Options  FollowSymLinks

#Indexes 的作用就是當該目錄下沒有 index.html 檔案時,就顯示目錄結構,去掉 Indexes,Apache 就不會顯示該目錄的列表了。


# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# 
  Options FileInfo AuthConfig Limit
#
 
   AllowOverride None

#
# Controls who can get stuff from this server.
#
 
   Order allow,deny
 
   Allow from all

</Directory>

3、儲存httpd.conf,並重啟Apache即可,此時再訪問http://localhost時, 報apache http 403 禁止訪問錯誤資訊

  Forbidden

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

   另一種方法是在指定的web目錄下:http://jwc.jxatei.net:8080/  "index.html、index.php時",也可解決訪問目錄問題,但沒有解決根本問題。 

  至此,通過配置Apache伺服器我們可以實現禁止目錄訪問(列出目錄或檔案清單),這些功能對提高和最佳化WEB伺服器的安全效能是必不可少的方法。


禁止訪問Apache目錄(2011-01-23 14:53:14)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.