<-
Apache > HTTP Server > 文件 > 2.4 版 > 模組

Apache 模組 mod_authn_core

可用的語言: en  |  fr 

說明核心驗證
狀態基本
模組識別碼authn_core_module
原始檔mod_authn_core.c
相容性可以在 Apache 2.3 以上的版本使用

摘要

此模組提供核心驗證功能,以允許或拒絕存取網站的部份內容。mod_authn_core 模組提供一些所有驗證提供者共用的指令。

Support Apache!

主題

指令

錯誤修正清單

請參閱

top

建立驗證提供者別名

可以建立進階驗證提供者並在設定檔中指派別名。之後便可以在 AuthBasicProviderAuthDigestProvider 指令使用該別名提供者,就像使用基本驗證提供者一樣。除了建立別名給進階提供者的功能之外,它也可以讓多個位置參照相同的進階驗證提供者。

範例

這個範例會在兩個不同的文字檔中檢查密碼。

檢查多個文字密碼檔

# Check here first
<AuthnProviderAlias file file1>
    AuthUserFile "/www/conf/passwords1"
</AuthnProviderAlias>

# Then check here
<AuthnProviderAlias file file2>   
    AuthUserFile "/www/conf/passwords2"
</AuthnProviderAlias>

<Directory "/var/web/pages/secure">
    AuthBasicProvider file1 file2
    
    AuthType Basic
    AuthName "Protected Area"
    Require valid-user
</Directory>

下面的範例會根據 ldap 提供者建立兩個不同的 ldap 驗證提供者別名。這會允許一個經過驗證的位置由多個 ldap 主機提供服務

檢查多個 LDAP 伺服器

<AuthnProviderAlias ldap ldap-alias1>
    AuthLDAPBindDN cn=youruser,o=ctx
    AuthLDAPBindPassword yourpassword
    AuthLDAPURL ldap://ldap.host/o=ctx
</AuthnProviderAlias>
<AuthnProviderAlias ldap ldap-other-alias>
    AuthLDAPBindDN cn=yourotheruser,o=dev
    AuthLDAPBindPassword yourotherpassword
    AuthLDAPURL ldap://other.ldap.host/o=dev?cn
</AuthnProviderAlias>

Alias "/secure" "/webpages/secure"
<Directory "/webpages/secure">
    AuthBasicProvider ldap-other-alias  ldap-alias1
    
    AuthType Basic
    AuthName "LDAP Protected Place"
    Require valid-user
    # Note that Require ldap-* would not work here, since the 
    # AuthnProviderAlias does not provide the config to authorization providers
    # that are implemented in the same module as the authentication provider.
</Directory>
top

AuthName 指令

說明授權範圍用於 HTTP 驗證
語法AuthName auth-domain
內容目錄、.htaccess
覆寫AuthConfig
狀態基本
模組mod_authn_core

此指令為目錄設定授權區域的名稱。此區域會提供給客戶端,讓使用者知道要傳送哪個使用者名稱與密碼。 AuthName會接收單一引數;如果區域名稱包含空格,則必須加上引號。必須搭配 AuthTypeRequire 指令,以及諸如 AuthUserFileAuthGroupFile 等指令才能運作。

例如

AuthName "Top Secret"

提供給 AuthName 的字串會顯示在大部分瀏覽器所提供的密碼對話框中。

從 2.4.55 起,可以使用指令內部的 運算式語法 來動態產生名稱。

例如

AuthName "%{HTTP_HOST}"

請參閱

top

<AuthnProviderAlias> 指令

說明將代表基本驗證提供者擴充的指令群圈起來,並由所指定的別名參照
語法<AuthnProviderAlias 基本提供者 別名> ... </AuthnProviderAlias>
內容伺服器設定
狀態基本
模組mod_authn_core

<AuthnProviderAlias></AuthnProviderAlias> 用來圈住驗證指令的群組,其中可以使用 AuthBasicProvider AuthDigestProvider 等指令來參照別名名稱。

此指令不會影響授權,即使對於同時提供驗證與授權的模組來說也是如此。
top

AuthType 指令

說明使用者驗證類型
語法AuthType None|Basic|Digest|Form
內容目錄、.htaccess
覆寫AuthConfig
狀態基本
模組mod_authn_core

此指令會選擇目錄的使用者驗證類型。可用的驗證類型為 NoneBasic(由 mod_auth_basic 實作)、Digest(由 mod_auth_digest 實作)以及 Form(由 mod_auth_form 實作)。

要實作驗證,您還必須使用 AuthNameRequire 指令。此外,伺服器必須具備驗證提供者模組,例如 mod_authn_file,以及授權模組,例如 mod_authz_user

驗證類型 None 會停用驗證。當啟用驗證時,它通常會由每個後續 設定區段 繼承,除非指定了不同的驗證類型。如果不需要對經過驗證的部分進行子部分驗證,可以使用驗證類型 None;在以下範例中,客戶端可以存取 /www/docs/public 目錄而不進行驗證

<Directory "/www/docs">
    AuthType Basic
    AuthName Documents
    AuthBasicProvider file
    AuthUserFile "/usr/local/apache/passwd/passwords"
    Require valid-user
</Directory>

<Directory "/www/docs/public">
    AuthType None
    Require all granted
</Directory>

在 2.4.55 之後,可以在指令內使用 表達式語法 來動態指定類型。

在停用驗證時,請注意,已針對伺服器文件樹的另一部分進行驗證的客戶端通常會繼續傳送驗證 HTTP 標頭或 Cookie,附在每個要求中,而不管伺服器是否實際上需要對每個資源進行驗證。

請參閱

可用的語言: en  |  fr 

top

評論

通知
這不是 Q&A 區段。放在這裡的評論應針對改善文件或伺服器的建議,如果這些評論已被實施或被視為無效/離題,我們的管理員可能會移除這些評論。有關如何管理 Apache HTTP 伺服器應導向我們的 IRC 頻道 #httpd(在 Libera.chat 上)或傳送到我們的 郵件清單