nginx 添加用户认证
nginx 配置文件添加;
配置代理添加用户认证:
server {
listen ;
server_name localhost;
location / {
auth_basic "secret";
auth_basic_user_file /etc/nginx/conf.d/passwd.db;
proxy_pass http://localhost:2018;
proxy_set_header Host $host:;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Via "nginx";
}
}
安装 http 插件:
yum install http -y
添加账户密码:(账户密码文件会存在刚才配置的 /etc/nginx/conf.d/passwd.db 中)
# htpasswd -b /etc/nginx/conf.d/passwd.db user1 passwd1
# htpasswd -b /etc/nginx/conf.d/passwd.db user2 passwd2
测试 http://ip/ 会有提示框 输入账户密码