Chinaunix首页 | 论坛 | 博客
  • 博客访问: 989327
  • 博文数量: 195
  • 博客积分: 4890
  • 博客等级: 上校
  • 技术积分: 2221
  • 用 户 组: 普通用户
  • 注册时间: 2009-06-09 15:34
文章分类

全部博文(195)

文章存档

2014年(1)

2013年(8)

2012年(22)

2011年(9)

2010年(54)

2009年(101)

我的朋友

分类: LINUX

2009-10-07 20:02:45

    [root@hnwt-jy-pds liyongfeng]# vi /etc/httpd/conf/httpd.conf
    第289行设置
    289
    290
    291 #
    292 # Possible values for the Options directive are "None", "All",
    293 # or any combination of:
    294 #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    295 #
    296 # Note that "MultiViews" must be named *explicitly* --- "Options All"
    297 # doesn't give it to you.
    298 #
    299 # The Options directive is both complicated and important.  Please see
    300 #
    301 # for more information.
    302 #
    303     Options Indexes FollowSymLinks
    304
    305 #
    306 # AllowOverride controls what directives may be placed in .htaccess files.
    307 # It can be "All", "None", or any combination of the keywords:
    308 #   Options FileInfo AuthConfig Limit
    309 #
    310     AllowOverride None
    311
    312 #
    313 # Controls who can get stuff from this server.
    314 #
    315     Order allow,deny
    316     Allow from all
    317
    318

 
    我试验使用的目录
    320
    321    Order deny,allow
    322    AllowOverride authconfig
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335

选项AllowOverride authconfig 开启.htaccess认证
 
[root@hnwt-jy-pds liyongfeng]# ll
总用量 4
-rw-r--r--  1 root root 6 10月  7 19:12 index.html
[root@hnwt-jy-pds liyongfeng]# pwd
/home/apache/focus/liyongfeng
[root@hnwt-jy-pds liyongfeng]#
 
到/home/apache/focus/liyongfeng目录下创建.htaccess文件
[root@hnwt-jy-pds liyongfeng]# vi .htaccess
并编辑内容如下
AuthName           "peiyongjun"
AuthType           basic
AuthUserFile       /home/apache/focus/liyongfeng/passwd
require            valid-user
 
AuthName   认证标题框显示内容
AuthType   访问apache用户身份验证资料使用unicode编码格式
AuthUserFile   认证调用的密码档案(需要使用命令创建)
require        必须经过验证的合法使用者才能存取网页
 
使用命令生成密码档案文件
[root@hnwt-jy-pds liyongfeng]# htpasswd ?
Usage:
        htpasswd [-cmdpsD] passwordfile username
        htpasswd -b[cmdpsD] passwordfile username password
        htpasswd -n[mdps] username
        htpasswd -nb[mdps] username password
 -c  Create a new file.
 -n  Don't update file; display results on stdout.
 -m  Force MD5 encryption of the password.
 -d  Force CRYPT encryption of the password (default).
 -p  Do not encrypt the password (plaintext).
 -s  Force SHA encryption of the password.
 -b  Use the password from the command line rather than prompting for it.
 -D  Delete the specified user.
On Windows, NetWare and TPF systems the '-m' flag is used by default.
On all other systems, the '-p' flag will probably not work.
[root@hnwt-jy-pds liyongfeng]# htpasswd -c passwd(建立密码档案文件名称) root(登录用户名)
New password:
Re-type new password:
Adding password for user root
[root@hnwt-jy-pds liyongfeng]# ls -al
总用量 20
drwxr-xr-x  2 root root 4096 10月  7 19:59 .
drwxr-xr-x  9 root root 4096 10月  7 19:12 ..
-rw-r--r--  1 root root  145 10月  7 19:40 .htaccess
-rw-r--r--  1 root root    6 10月  7 19:12 index.html
-rw-r--r--  1 root root   19 10月  7 19:59 passwd
[root@hnwt-jy-pds liyongfeng]#
service httpd restart后即可打开网页测试,使用用户名root和密码即可浏览网页
 
 
阅读(1399) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~