nginx 增加HTTP Auth Basic模塊

nginx_http_auth_basic_module

該模塊可以使你使用用戶名和密碼基於 HTTP 基本認證方法來保護你的站點或其部分內容。

__實例配置__

location / {
: auth_basic "Restricted";
: auth_basic_user_file conf/htpasswd;
}
指令

[#auth_basic auth_basic]
[#auth_basic_user_file auth_basic_user_file]
auth_basic

語法: auth_basic [ text|off ]

默認值: auth_basic off

作用域: http, server, location, limit_except

該指令包含用於 HTTP 基本認證 的測試名和密碼。分配的參數用於認證領域。值 "off" 可以使其覆蓋來自上層指令的繼承性。

auth_basic_user_file

語法: auth_basic_user_file the_file

默認值: no

作用域: http, server, location, limit_except

該指令爲某認證領域指定 htpasswd 文件名。

文件格式類似於下面的內容:

用戶名:密碼
用戶名2:密碼2:註釋
用戶名3:密碼3
密碼必須使用函數 crypt(3) 加密。你可以使用來自 Apache 的 htpasswd 工具來創建密碼文件。

你也可以使用perl 創建密碼文件,pw.pl 的內容:

#!/usr/bin/perl
use strict;

my $pw=$ARGV[0] ;
print crypt($pw,$pw)."\n";
然後執行

chmod +x pw.pl
./pw.pl password
papAq5PwY/QQM
papAq5PwY/QQM 就是password 的crypt()密碼
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章