Nginx HTTP Auth Basic 模塊

2018-10-27 19:44 更新

ngx_http_auth_basic_module

該模塊可以使你使用用戶名和密碼基于 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]

Template:Anchor

auth_basic

語(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)自上層指令的繼承性。

Template:Anchor

auth_basic_user_file

語(yǔ)法: auth_basic_user_file the_file

默認(rèn)值: no

作用域: http, server, location, limit_except

該指令為某認(rèn)證領(lǐng)域指定 htpasswd 文件名。

文件格式類(lèi)似于下面的內(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()密碼




以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)