Apache HTTP Server 2.4 版
說明 | 核心驗證 |
---|---|
狀態 | 基本 |
模組識別碼 | authn_core_module |
原始檔 | mod_authn_core.c |
相容性 | 可以在 Apache 2.3 以上的版本使用 |
此模組提供核心驗證功能,以允許或拒絕存取網站的部份內容。mod_authn_core
模組提供一些所有驗證提供者共用的指令。
可以建立進階驗證提供者並在設定檔中指派別名。之後便可以在 AuthBasicProvider
或 AuthDigestProvider
指令使用該別名提供者,就像使用基本驗證提供者一樣。除了建立別名給進階提供者的功能之外,它也可以讓多個位置參照相同的進階驗證提供者。
這個範例會在兩個不同的文字檔中檢查密碼。
# 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 主機提供服務
<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>
說明 | 授權範圍用於 HTTP 驗證 |
---|---|
語法 | AuthName auth-domain |
內容 | 目錄、.htaccess |
覆寫 | AuthConfig |
狀態 | 基本 |
模組 | mod_authn_core |
此指令為目錄設定授權區域的名稱。此區域會提供給客戶端,讓使用者知道要傳送哪個使用者名稱與密碼。 AuthName
會接收單一引數;如果區域名稱包含空格,則必須加上引號。必須搭配 AuthType
與 Require
指令,以及諸如 AuthUserFile
與 AuthGroupFile
等指令才能運作。
例如
AuthName "Top Secret"
提供給 AuthName
的字串會顯示在大部分瀏覽器所提供的密碼對話框中。
從 2.4.55 起,可以使用指令內部的 運算式語法 來動態產生名稱。
例如
AuthName "%{HTTP_HOST}"
說明 | 將代表基本驗證提供者擴充的指令群圈起來,並由所指定的別名參照 |
---|---|
語法 | <AuthnProviderAlias 基本提供者 別名> ... </AuthnProviderAlias> |
內容 | 伺服器設定 |
狀態 | 基本 |
模組 | mod_authn_core |
<AuthnProviderAlias>
與 </AuthnProviderAlias>
用來圈住驗證指令的群組,其中可以使用 AuthBasicProvider
或 AuthDigestProvider
等指令來參照別名名稱。
說明 | 使用者驗證類型 |
---|---|
語法 | AuthType None|Basic|Digest|Form |
內容 | 目錄、.htaccess |
覆寫 | AuthConfig |
狀態 | 基本 |
模組 | mod_authn_core |
此指令會選擇目錄的使用者驗證類型。可用的驗證類型為 None
、Basic
(由 mod_auth_basic
實作)、Digest
(由 mod_auth_digest
實作)以及 Form
(由 mod_auth_form
實作)。
要實作驗證,您還必須使用 AuthName
與 Require
指令。此外,伺服器必須具備驗證提供者模組,例如 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 之後,可以在指令內使用 表達式語法 來動態指定類型。