用户授权和认证

在打开网页弹出用户名及密码认证对话框( apache 版本是: httpd-suexec-2.0.52-41.ent )特别标注出来版本是因为先后做过两台服务器出的问题不一样,一台 apache 版本为 httpd-2.0.52-9.ent 的比 httpd-suexec-2.0.52-41.ent httpd.conf 中要多出一些设置。

一、先说 httpd-suexec-2.0.52-41.ent 版本的( 2101-5-4

第一步修改 httpd.conf
修改的这段大概httpd.conf 291~320

<Directory "/var/www/html">   // 改为自己网页文件所在目录,我的是在home 下建了一个http 目录所以我的改为<Directory “/home/http”>

 

#
# Possible values for the Options directive are "None", "All",
# or any combination of:
#   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important.  Please see
# http://httpd.apache.org/docs-2.0/mod/core.html#options
# for more information.
#
    Options Indexes FollowSymLinks

 

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   Options FileInfo AuthConfig Limit
#
    AllowOverride None  // 将这句改为AllowOverride All ,这样.htaccess 文件才会起作用

 

#
# Controls who can get stuff from this server.
#
    Order allow,deny
    Allow from all

 

</Directory>
确认 AccessFileName .htaccess (这段大概在 httpd.conf 385 行)
AccessFileName .htaccess
第二步:建立 .htaccess 文件
这个文件也可以是任何名称,可以放在任何认为合适的位置,我是放在 /home/http
#cd home/http
[root@linux http]#vi .htaccess
输入以下内容
AuthUserFile 用户帐号密码文件名
AuthGroupFile 群组帐号密码文件名
AuthName 画面提示文字
AuthType 验证方式
用户验证方式 AuthType 目前提供了 Basic Digest 两种。

密码检验设定方法与 httpd.conf 中的相关设定相同。

我输入的是:
AuthUserFile /etc/setureuser // 这个 setureuser 是我在后面建立的存放认证用户用户名及密码的文件
AuthName UserLogin // 这个随便起名,这只是弹出对话框的题目
AuthType Basic // 用户认证的方式
require valid-user // valid-user 参数意味着 user 文件中的所有用户都是可用的。

(#require valid-user 或者 require user frank 限制是所有合法用户还是指定用户 )

wq!  // 保存退出
因为我没有设置组群,所以就没在写 AuthGroupFile 的设置,如果想设置组群
第三步:建立用户
#htpasswd –c /etc/setureuser icedot // 这是我建立了一个 setureuser 的密码文件,用来存储认证访问用户的用户名及密码, icedot 是新建的用户的用户名,回车确认后系统会要求给用户输入密码及确认密码。
第一次建立用户时需要用 -c 这个参数,以后再加入新的用户时就不用了
想修改密码,可以如下
#htpasswd -m /etc/setureuser icedot

最后重启 httpd
#etc/init.d/httpd restart
二、再说 httpd-2.0.52-9.ent 版本的( 2101-5-6

今天( 2010-5-6 )新做另一台服务器的 MRTG 时遇到了一个问题,前面做的三步与 5 4 日做的服务器的步骤一样,一切顺利,但到做完后打开网页弹出了用户认证对话框开始出错了,输入用户名和密码后不行,始终弹出对话框,我将 .htaccess 、用户密码文件,权限也改过,也新建过,始终不行,进入 var/log/http/ 下查看 error_log 发现报错,这台服务器的 apache 的版本是 httpd-2.0.52-9.ent
[Thu May 06 22:14:50 2010] [error] [client 123.116.103.53] MySQL ERROR: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

[Thu May 06 22:14:50 2010] [error] [client 123.116.103.53] MySQL user icedot not found: /

从报错上来看就是说系统在验证用户时并没有到我设定的密码文件中去找查找,而是到 mysql 里去查找用户,于是通过 /etc/init.d/mysql status 命令查看是否有 mysql 运行,发现 mysql 是没有启动的,想来还是 httpd.conf 的问题,查到后来解决的办法
这段大概在 275~278 之间
<Directory />
Options All
AllowOverride None
</Directory>
------------------------------------------------------- 改为 --------------------------------------------------------
<Directory />
Options All

AuthMySQLEnable off // 这句是新加上去的,就是为了关闭web mysql 里查找用户

AllowOverride None
</Directory>
就是在中间加了一句让 Mysql 关闭
再打开网页,通过验证进入页面恢复正常。

这两次不一样可能是由于apache的版本不一样的原因

狂试狂改狂查资料两天不成功,不是不成功,今天终于成功了,我吐……