該模塊可以使你使用用戶名和密碼基于 HTTP 基本認(rèn)證方法來(lái)保護(hù)你的站點(diǎn)或其部分內(nèi)容。
__實(shí)例配置__
location / { : auth_basic "Restricted"; : auth_basic_user_file conf/htpasswd; }
[#auth_basic auth_basic]
[#auth_basic_user_file auth_basic_user_file]
語(yǔ)法: auth_basic [ text|off ]
默認(rèn)值: auth_basic off
作用域: http, server, location, limit_except
該指令包含用于 HTTP 基本認(rèn)證 的測(cè)試名和密碼。分配的參數(shù)用于認(rèn)證領(lǐng)域。值 "off" 可以使其覆蓋來(lái)自上層指令的繼承性。
語(yǔ)法: auth_basic_user_file the_file
默認(rèn)值: no
作用域: http, server, location, limit_except
該指令為某認(rèn)證領(lǐng)域指定 htpasswd 文件名。
文件格式類似于下面的內(nèi)容:
用戶名:密碼 用戶名2:密碼2:注釋 用戶名3:密碼3
密碼必須使用函數(shù) crypt(3) 加密。 你可以使用來(lái)自 Apache 的 htpasswd 工具來(lái)創(chuàng)建密碼文件。
你也可以使用perl 創(chuàng)建密碼文件,pw.pl 的內(nèi)容:
#!/usr/bin/perl use strict; my $pw=$ARGV[0] ; print crypt($pw,$pw)."\n";
然後執(zhí)行
chmod +x pw.pl ./pw.pl password papAq5PwY/QQM
papAq5PwY/QQM 就是password 的crypt()密碼
更多建議: