| Syntax: | auth_basic string | off;

    | | —- | —- | | Default: | auth_basic off; | | Context: | http, server, location, limit_except

    |

    设置为 auth_basic “nginx auth”;
    开启使用“HTTP基本认证”协议的用户名密码验证。 指定的参数被用作域。 参数off可以取消继承自上一个配置等级 auth_basic 指令的影响
    image.png

    | Syntax: | auth_basic_user_file file;

    | | —- | —- | | Default: | — | | Context: | http, server, location, limit_except

    |

    指定保存用户名和密码的文件,格式:
    # comment
    name1:password1
    name2:password2:comment
    name3:password3

    密码应该使用crypt()函数加密
    可以用Apache发行包中的 htpasswd 命令来创建此类文件

    使用openssl命令创建密码:
    openssl passwd -crypt 123456
    image.png