Nginx/HttpAuth

来自OSSmedia

本文介绍如何配置 Nginx 的http basic auth

Ubuntu/debian

软件包
sudo apt instal apache2-utils
创建密码文件
sudo htpasswd -c /etc/apache2/.htpasswd user1
创建第二个用户,因为文件已经存在,所以不需要 -c 参数
sudo htpasswd /etc/apache2/.htpasswd user2

nginx 配置文件

location /api {
   auth_basic           "Administrator’s Area";
   auth_basic_user_file /etc/apache2/.htpasswd; 
}