📄 auth.html
字号:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="keywords" content="Apache, 中文, 手册, 中文版, 中文手册, 中文版手册, 参考手册, 中文参考手册, 金步国" />
<meta name="description" content="Apache 2.2 中文版参考手册" />
<meta name="author" content="金步国" />
<link href="../style/css/manual-zip.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
<link href="../style/css/manual-zip-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
<link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
<title>认证、授权、访问控制 - Apache 2.2 中文版参考手册</title>
</head>
<body id="manual-page"><div id="page-header">
<p class="menu"><a href="../mod/index.html">模块索引</a> | <a href="../mod/directives.html">指令索引</a> | <a href="../faq/index.html">常见问题</a> | <a href="../glossary.html">词汇表</a> | <a href="../sitemap.html">站点导航</a></p><p class="apache">Apache HTTP Server 版本2.2</p><img alt="" src="../images/feather.gif" /></div>
<div class="up"><a href="./index.html"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
<div id="path"><a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">文档</a> > <a href="../index.html">版本2.2</a> > <a href="./index.html">如何.../指南</a></div>
<div id="translation-info"> <a href="../translator_announcement.html#thanks">致谢</a> | <a href="../translator_announcement.html#announcement">译者声明</a> | 本篇译者:<a href="mailto:csfrank@citiz.net">金步国</a> | 本篇译稿最后更新:2006年1月8日 | <a href="../translator_announcement.html#last_new">获取最新版本</a></div>
<div id="page-content"><div id="preamble"><h1>认证、授权、访问控制</h1>
<p>认证(Authentication)是指任何识别用户身份的过程。授权(Authorization)是允许特定用户访问特定区域或信息的过程。</p>
</div>
<div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="related" id="related">相关模块和指令</a></h2>
<p>认证和授权涉及到三组模块。通常,你需要从每一组中选择至少一个模块。</p>
<ul>
<li>认证类型模块(参见<code class="directive"><a href="../mod/core.html#authtype">AuthType</a></code>指令)
<ul>
<li><code class="module"><a href="../mod/mod_auth_basic.html">mod_auth_basic</a></code></li>
<li><code class="module"><a href="../mod/mod_auth_digest.html">mod_auth_digest</a></code></li>
</ul>
</li>
<li>认证支持模块
<ul>
<li><code class="module"><a href="../mod/mod_authn_alias.html">mod_authn_alias</a></code></li>
<li><code class="module"><a href="../mod/mod_authn_anon.html">mod_authn_anon</a></code></li>
<li><code class="module"><a href="../mod/mod_authn_dbd.html">mod_authn_dbd</a></code></li>
<li><code class="module"><a href="../mod/mod_authn_dbm.html">mod_authn_dbm</a></code></li>
<li><code class="module"><a href="../mod/mod_authn_default.html">mod_authn_default</a></code></li>
<li><code class="module"><a href="../mod/mod_authn_file.html">mod_authn_file</a></code></li>
<li><code class="module"><a href="../mod/mod_authnz_ldap.html">mod_authnz_ldap</a></code></li>
</ul>
</li>
<li>授权支持模块(参见<code class="directive"><a href="../mod/core.html#require">Require</a></code>指令)
<ul>
<li><code class="module"><a href="../mod/mod_authnz_ldap.html">mod_authnz_ldap</a></code></li>
<li><code class="module"><a href="../mod/mod_authz_dbm.html">mod_authz_dbm</a></code></li>
<li><code class="module"><a href="../mod/mod_authz_default.html">mod_authz_default</a></code></li>
<li><code class="module"><a href="../mod/mod_authz_groupfile.html">mod_authz_groupfile</a></code></li>
<li><code class="module"><a href="../mod/mod_authz_owner.html">mod_authz_owner</a></code></li>
<li><code class="module"><a href="../mod/mod_authz_user.html">mod_authz_user</a></code></li>
</ul>
</li>
</ul>
<p><code class="module"><a href="../mod/mod_authnz_ldap.html">mod_authnz_ldap</a></code>模块既包含认证功能也包含授权功能。<code class="module"><a href="../mod/mod_authn_alias.html">mod_authn_alias</a></code>模块自身并不实现认证功能,但是允许其它认证支持模块以更灵活的方式进行配置。</p>
<p><code class="module"><a href="../mod/mod_authz_host.html">mod_authz_host</a></code>模块提供基于主机名、IP地址、请求特征的访问控制,但并不属于认证支持系统。</p>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="introduction" id="introduction">简介</a></h2>
<p>如果网站上有些敏感信息或只希望为一个小群体所访问,本文阐述的方法能确保用户只能访问被允许的资源。</p>
<p>本文涵盖了保护站点资源的"标准"方法,大多数管理员将要用到这些方法。</p>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="theprerequisites" id="theprerequisites">先决条件</a></h2>
<p>本文中讨论的指令应该被放进主配置文件(通常在<code class="directive"><a href="../mod/core.html#directory"><Directory></a></code>段中)或者针对单个目录的配置文件(<code>.htaccess</code>文件)中。</p>
<p>如果你打算使用<code>.htaccess</code>文件,则必须设置服务器以允许在这些文件中使用认证指令,即用<code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code>指令指定哪些指令在针对单个目录的配置文件中有效。</p>
<p>既然本文讨论认证,就应该对<code class="directive"><a href="../mod/core.html#allowoverride">AllowOverride</a></code>这样设置:</p>
<div class="example"><p><code>
AllowOverride AuthConfig
</code></p></div>
<p>如果你希望把这些指令直接写入主配置文件,当然就需要具有对主配置文件的写权限。</p>
<p>而且,你需要对服务器的目录结构有所了解,以确定某些文件的位置。这个并不难,需要时我们会做适当的说明。</p>
</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
<div class="section">
<h2><a name="gettingitworking" id="gettingitworking">启用认证</a></h2>
<p>先介绍用密码来保护服务器上的目录。</p>
<p>首先需要建立一个密码文件。这个文件应该放在不能被网络访问的位置,以避免被下载。例如,如果<code>/usr/local/apache/htdocs</code>以外的空间不能被网络访问,那么可以考虑把密码文件放在<code>/usr/local/apache/passwd</code>目录中。</p>
<p>Apache在其安装目录的<code>bin</code>子目录中提供了<code class="program"><a href="../programs/htpasswd.html">htpasswd</a></code>工具,用于建立密码文件,可以这样使用:</p>
<div class="example"><p><code>
htpasswd -c /usr/local/apache/passwd/passwords rbowen
</code></p></div>
<p><code class="program"><a href="../programs/htpasswd.html">htpasswd</a></code>会要你输入密码,并要求重新输入以进行确认:</p>
<div class="example"><p><code>
# htpasswd -c /usr/local/apache/passwd/passwords rbowen<br />
New password: mypassword<br />
Re-type new password: mypassword<br />
Adding password for user rbowen
</code></p></div>
<p>如果<code class="program"><a href="../programs/htpasswd.html">htpasswd</a></code>不在搜索路径中,则必须使用完整路径,如:<code>/usr/local/apache/bin/htpasswd</code></p>
<p>然后修改<code>httpd.conf</code>或<code>.htaccess</code>文件,指示服务器允许哪些用户访问并向用户索取密码。若要保护<code>/usr/local/apache/htdocs/secret</code>目录,则可以将下列指令写入<code>/usr/local/apache/htdocs/secret/.htaccess</code>或者<code>httpd.conf</code>的<Directory
/usr/local/apache/apache/htdocs/secret>段。</p>
<div class="example"><p><code>
AuthType Basic<br />
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -