[英]Apache2 locations: deny root, allow path
我有一個配置,我希望阻止用戶訪問根目錄
<VirtualHost *:443>
ServerName foo.com
DocumentRoot /var/www
<Location "/">
Require all denied
</Location>
<Location "/bar">
Require all granted
</Location>
</VirtualHost>
如果我將第一個路徑更改為/bar
並將第二個路徑更改為/bar/baz
這有效( /bar
被阻止, /bar/baz
是允許的)但將其減少到根目錄並沒有預期的效果 - /
, /bar
和確實,“foo.com”的任何路徑都被拒絕了。
我該怎么做才能允許這種結構,其中只有具有特定路徑的特定域有效,其他一切都被拒絕(或錯誤,或者對客戶端不起作用)
注意:這適用於 Apache 2.4,適用於Location
而不是Directory
(因為它指向的應用程序使用固定索引和 mod_rewrite 將路徑傳遞給路由器)
我在hosts
文件中介紹了這些條目
127.0.0.1 www.daffyduck.com
127.0.0.1 www.tomandjerry.com
然后我把這些配置
<VirtualHost _default_:443>
DocumentRoot "C:/MyFiles/xampp/htdocs/tomandjerry"
ServerName www.tomandjerry.com:443
<Location "/">
Require all denied
</Location>
<LocationMatch "(/bar1.*|/bar1/.*)">
Require all granted
</LocationMatch>
</VirtualHost>
<VirtualHost _default_:443>
DocumentRoot "C:/MyFiles/xampp/htdocs/daffyduck"
ServerName www.daffyduck.com:443
<Location "/">
Require all denied
</Location>
<LocationMatch "(/bar2.*|/bar2/.*)">
Require all granted
</LocationMatch>
</VirtualHost>
如果我輸入https://www.daffyduck.com/
我得到You don't have permission to access this resource.
如果我輸入https://www.daffyduck.com/bar2/
那么我得到 index.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.