# 安装 htpasswd 工具
yum install httpd-tools -y
# 生成密码文件
htpasswd -bc /usr/local/nginx/conf/.passwd usera pwd # 创建用户usera, 并写入 .passwd
htpasswd -b /usr/local/nginx/conf.passwd userb pwd # 追加用户 userb
htpasswd -D /usr/local/nginx/conf/.passwd usera # 删除用户
# nginx配置
server {
listen 80;
server_name xxx.com;
index index.html;
location /auth {
auth_basic "nginx auth";
auth_basic_user_file /usr/local/nginx/conf/.passwd;
alias /export/webapps/xxx.com;
}
}