Chinaunix首页 | 论坛 | 博客
  • 博客访问: 485694
  • 博文数量: 82
  • 博客积分: 3003
  • 博客等级: 中校
  • 技术积分: 1285
  • 用 户 组: 普通用户
  • 注册时间: 2007-09-11 15:27
文章分类

全部博文(82)

文章存档

2011年(1)

2010年(5)

2009年(63)

2008年(13)

我的朋友

分类: LINUX

2009-11-02 12:22:21

1,配置主配置文件

[root@server2 conf]# vim httpd.conf

#

# UserDir is disabled by default since it can confirm the presence

# of a username on the system (depending on home directory

# permissions).

#

UserDir public_html ####允许定义个人用户首页####

#

# To enable requests to /~user/ to serve the user's public_html

# directory, remove the "UserDir disable" line above, and uncomment

# the following line instead:

#



Alias /user/ "/home/user/public_html/" ###可以在此做一个别名,这样的话直接输入就可以链接到加了认证的页面了###

AllowOverride AuthConfig ##可以使用AuthConfig的设定在.htaccess这个档案中,.htaccess文件不用重启服务就会生效###


DirectoryIndex index.html index.html.var ###这是指定的首页文件###

AccessFileName .htaccess

#

# The following lines prevent .htaccess and .htpasswd files from being

# viewed by Web clients.

#

Order allow,deny

Deny from all

[root@server2 conf]# service httpd restart


2配置用户首页

[root@server2 user]#mkdir public_html/

[root@server2 conf]# cd public_html/

[root@server2 public_html]# ls

index.html test

[root@server2 public_html]# vim index.html

####文件与DirectoryIndex的匹配

做用户的个人首页的时候,首页文件一定要与http.conf中规定的

DirectoryIndex index.html index.html.var

首页文件名与该文件对应起来。####

Hahahaha


3,配置.htaccess文件(家目录下)

[root@server2 public_html]# vim .htaccess

Authname "protect test" ###提示框的提示字符###

AuthType Basic ###认证的类型###

AuthUserFile /home/user/user.passwd ####保护目录所使用的账号密码的设置文件####

require user yoko ###后接可以使用的账号,如果要让密码文件内的用户都能够登录,将其改为“require valid-user”###


4,创建密码保护文件

[root@server2 public_html]# cd ..

[root@server2 user]# ls

[root@server2 user]# htpasswd -c user.passwd yoko ###创建user.passwwd记录yoko的密码,注文件名要与AuthFileName一致且不要放在可浏览的目录内###

New password:

Re-type new password:

Adding password for user yoko

[root@server2 user]# htpasswd user.passwd user ###user.passwd里添加用户和密码,注意不要加-C###

New password:

Re-type new password:

Adding password for user user

[root@server2 user]# cat user.passwd

yoko:V7zAnee3r8/Nc

user:LEANKVgK7JUWM


5,验证








后续:

还可以将http.conf.htaccess一起,使授权和认证结合使用,只需要在以上实验基础上

1[root@server2 conf]# vim httpd.conf

AllowOverride AuthConfig

order deny,allow

deny from 192.168.20.2

###Order deny,allow allow的会覆盖deny的,什么都不写的话默认为allow

Order allow,deny deny的会覆盖allow的,什么都不写的话默认为deny

###

[root@server2 conf]# service httpd restart


2[root@server2 public_html]# vim .htaccess

Authname "protect test"

AuthType Basic

AuthUserFile /home/user/user.passwd

require user yoko

satisfy all ###,指两者都要满足,若为satisfy any,则授权和认证满足任何一个即可###


3,验证

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