nginx HttpAuthBasicModule 身份认证配置 auth_basic

http://wiki.nginx.org/HttpAuthBasicModule

1. 首先生成密码

Passwords must be encoded by function crypt(3). If Apache is installed, you can create the password file using the htpasswd program included.

crypt() 函数在php、perl里均有,盐值与input一样就可以。

<?php
echo crypt($argv[1], $argv[1]),"\n";
?>


2. 添加至配置文件

nginx.conf 配置里添加

location  /  {
  auth_basic            "Restricted";
  auth_basic_user_file  htpasswd;
}


这里要保证 htpasswd 这个文件可以被找到。
一把保存至 /usr/local/nginx/conf/htpasswd
这个文本文件就是记录  用户名:加密密码

3. reload nginx

原文地址:https://www.cnblogs.com/cloudstorage/p/2588162.html