|
Tuesday, 15 May 2007 08:00 |
apache服务器中文件或目录的密码的保护网上有不少介绍了,这里稍微总结一下:
1.服务器的设置,主要有两种方法:
(1) 修改.htaccess文件。,比如加入
AuthName "Restricted"
AuthType Basic
AuthUserFile /path/to/.htpasswd
require valid-user
(2)修改apache的httpd.conf文件,比如加入
Alias /bytea /usr/local/bytea/share
<Directory "/usr/local/bytea/share">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Bytea.net"
AuthType Basic
AuthGroupFile /dev/null
AuthUserFile /usr/local/bytea/etc/.htpasswd
Require valid-user
</Directory>
注意上面只是例子
2. 创建.htpasswd文件,格式是username:encryptedpassword
可以用命令htpasswd -c /path/to/.htpasswd username 来创建
也可以用网上的一些工具来帮忙,比如.htpasswd creator
3. 重启apache就可以了
下面说说注意事项:
1. .htpasswd文件别放在apache的www目录里
2. apache要启用mod_auth 和 mod_authz_user。 第二个文件在debian里折腾了我半天,不知道其他系统里有没有,如果没启用第二个mod,会导致输入正确的密码之后还是不能登录
3. 如果还有问题,那么可能是encryption不同,试试改 htpasswd的参数
4. last and least 确定apache支持.htaccess rewrite
|