我试图解决如何保护Apache 2.4中的文件夹。
我有这部分工作正常:
AuthUserFile /home/test/web/site.com/cgi-bin/hotels/admin/.htpasswd AuthGroupFile /dev/null AuthType Basic AuthName Protected require valid-user
…但是我也想添加让我无需login的选项。 这是我在我的旧服务器上:
Order Deny,Allow Deny from all Allow from 123.123.123.123 Satisfy Any
但是新的给出了一个错误:
client denied by server configuration: /home/test/web/site.com/cgi-bin/hotels/admin/admin.cgi
看看https://wiki.apache.org/httpd/ClientDeniedByServerConfiguration ,我会认为这将工作:
Require all denied Allow from 123.123.123.123 Satisfy Any
…但它似乎并不(现在甚至不要求login,即使我将接受的IP更改为随机的IP)
我错过了什么?
不要混用这样的2.2和2.4指令。 满足/顺序/允许/拒绝都是2.2.x
仅使用2.4并卸载mod_access_compat:
AuthType Basic AuthName "Authorized Users Only" AuthBasicProvider file AuthUserFile /home/test/web/site.com/cgi-bin/hotels/admin/.htpasswd <RequireAny> Require valid-user Require ip 123.123.123.123 </RequireAny>
注意:htaccess与目录保护无关,如果你有权访问apache httpd服务器的主要configuration文件,在<Directory /filesystem/path/to/protected/dir>标签中定义这些<Directory /filesystem/path/to/protected/dir>
注2:忘记提及,RequireAny是为了示例的目的而被指定的,但这是2.4.x中的默认行为,所以如果你不需要的话,你不需要指定它。