Chinaunix首页 | 论坛 | 博客
  • 博客访问: 60910
  • 博文数量: 9
  • 博客积分: 1485
  • 博客等级: 上尉
  • 技术积分: 99
  • 用 户 组: 普通用户
  • 注册时间: 2006-01-04 13:21
文章分类
文章存档

2009年(3)

2008年(3)

2006年(3)

我的朋友
最近访客

分类: LINUX

2006-01-04 13:43:39

apache用户验证
 
1、安装时需要加载的模块
--enable-module=auth --enable-module=auth_db 
2、创建需要的目录
mkdir /www/auth
mkdir /www/authdb
chown nobody:nobody /www/auth /www/authdb

3、编辑httpd.conf
Alias /auth /www/auth
Alias /authdb /www/authdb

   AllowOverride AuthConfig


  AllowOverride Authconfig

AuthType Basic
4、在/www/auth,/www/authdb中分别创建.htaccess文件
vi /www/auth/.htaccess
AuthName "password file auth"
AuthUserFile /www/authfile/password
AuthGroupFile /www/authfile/group
Require group test
vi /www/authdb/.htaccess
AuthName "db auth"
AuthDBUserFile /www/authfile/dbuser.dat
Require username1

5、创建密码文件
/www/bin/htpasswd -c /www/authfile/password username1
/www/bin/htpasswd /www/authfile/password username2
创建组文件
echo "test: username1 username2" >> /www/authfiile/group

 
简洁版:
 
第1步:

我们在/var/www(apache的主页根目录)下建立一个test目录

mkdir /var/www/test

第2步

然后我们编辑httpd.conf

添加
Alias /test"/var/www/test"

Options Indexes MultiViews
AllowOverride AuthConfig #表示进行身份验证
Order allow,deny
Allow from all



#AllowOverride AuthConfig 表示进行身份验证 这是关键的设置 

第3步

在/var/www/test创建.htaccess文件
vi /var/www/test/.htaccess

AuthName "frank share web" 
AuthType Basic 
AuthUserFile /var/www/test/.htpasswd
require valid-user 

 

#AuthName 描述,随便写
#AuthUserFile /var/www/test/.htpasswd
#require valid-user 或者 require user frank 限制是所有合法用户还是指定用户

#密码文件推荐使用.htpasswd,因为apache默认系统对“.ht”开头的文件默认不允许外部读取,安全系数会高一点哦。

第4步

就是创建apache的验证用户

htpasswd -c /var/www/test/.thpasswd frank

#第一次创建用户要用到-c 参数 第2次添加用户,就不用-c参数

如果你们想修改密码,可以如下

htpasswd -m .htpasswd frank

 

第5步:

ok,重启apache服务,然后访问 http://你的网站地址/test 如果顺利的话,应该能看到一个用户验证的弹出窗口,只要填入第4步创建的用户名和密码就行

 

后话,为了服务器的性能,一般不推荐使用AllowOverride AuthConfig或者AllowOverride ALL,因为这会使服务器会不断的去寻找.htaccess,从而影响服务器的效能,一般我们把一些后台管理界面或者其他特殊目录可能需要加验证这个需求。

阅读(2338) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~