JAVA和Nginx 教程大全

网站首页 > 精选教程 正文

Nginx学习笔记(07) 限制特定用户访问的 auth_basic 模块

wys521 2024-10-05 04:47:00 精选教程 18 ℃ 0 评论

基本功能

基于HTTP Basic Authentication协议进行用户名密码认证
默认已编译进Nginx
    通过 --without-http_auth_basic_module禁用

指令

语法: auth_basic string | off;
默认值: auth_basic off;
上下文: http server location limit_except

语法: auth_basic_user_file file;
默认值: -
上下文: http server location limit_except

密码文件生成工具(htpasswd)

# 查看 htpasswd 命令的位置
whereis htpasswd 
# 安装命令
yum install -y httpd-tools
可执行程序:    htpasswd
所属软件包:    httpd-tools
生成新的密码文件:    htpasswd -bc encrypt_pass jack 123456 
添加新用户密码:    htpasswd -b encrypt_pass mike 123456 

基本配置

  • 首先在nginx/html路径下创建bbs/index.html
  • 配置nginx.conf
        location  /bbs/ {
            auth_basic "test user pass";
           # 指向密码文件
            auth_basic_user_file /www/server/nginx/auth/encrypt_pass;
            root html;
            index index.html;
        }



演示效果

访问路径: http://www.jabberwocky.cn/bbs/


输入账号密码点击登录,进入我们预先配置好的页面


Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表