簡體   English   中英

Apache 2.4 - 如何拒絕對 DocumentRoot 的訪問,但允許對 DirectoryIndex 文件的“尾部斜杠”訪問

[英]Apache 2.4 - How to deny access to DocumentRoot but allow 'trailing slash' access to DirectoryIndex file

在我的 Apache 2.4 VirtualHost 配置中,我想 - 默認情況下 - 拒絕訪問我沒有明確啟用的DocumentRoot中的所有內容。 為此,我寫道:

DocumentRoot /var/www
<Directory "/var/www">
  Require all denied 
  <Files "index.html">
    Require all granted
  </Files>
</Directory>

這允許直接訪問http://myserver.example/index.html ,但會導致403響應間接訪問http://myserver.example/

我該如何糾正這種行為?

遵循我“沒有明確允許/ ”的提示,導致它被禁止讓我走上解決這個問題的正確軌道。 添加專門處理尾部斜杠的LocationMatch指令會導致所需的行為:

DocumentRoot /var/www
<Directory "/var/www/">
  Require all denied
  <Files "index.html">
    Require all granted
  </Files>
</Directory>

# Regex anchored at string beginning and end
# -> only matches "/"
<LocationMatch "^/$">
  Require all granted
</LocationMatch>

請注意,添加<Files "/">指令不起作用,可能是因為訪問的資源不是真正的文件。 <Location />也不是正確的,因為它將應用於整個 VirtualHost。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM