nginx 添加用户认证

nginx 添加用户认证 

nginx 配置文件添加;

配置代理添加用户认证:
server {   listen      
80;   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:2018;      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/ 会有提示框 输入账户密码

posted @ 2019-08-20 17:07  01234567  阅读(1252)  评论(0编辑  收藏  举报