那么 在 nginx.conf 文件中對(duì)應(yīng)的 server 段中 添加
location ^~ /test/ {
auth_basic TEST-Login;
auth_basic_user_file /root/htpasswd;
再在 root 的主目錄中 /root/ 創(chuàng)建一個(gè)新文件 htpasswd
此文件的書(shū)寫(xiě)格式是
用戶(hù)名:密碼
每行一個(gè)賬戶(hù)
并且 密碼必須使用函數(shù) crypt(3) 加密
官方檔說(shuō) 可以用 Apache 的 htpasswd 工具來(lái)創(chuàng)建密碼文件
當(dāng)然也可以使用perl 創(chuàng)建密碼文件 新建 一個(gè) pw.pl 文件 其內(nèi)容:
復(fù)制代碼 代碼如下:
#!/usr/bin/perl
use strict;
my $pw=$ARGV[0] ;
print crypt($pw,$pw).”n”;
新聞熱點(diǎn)
疑難解答
圖片精選