nginx 添加用户认证

作者: siediyer 分类: linux 发布时间: 2021-08-29 16:32

配置代理添加用户认证:

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/ 会有提示框 输入账户密码

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

Title - Artist
0:00