access 模块

示例从上向下匹配

location / {
deny 192.168.1.1;
allow 192.168.1.0/24;
allow 10.1.1.0/16;
allow 2001:0db8::/32;
deny all;
}

  auth_basic模块 基于用户名密码做认证

安装http-tools 工具

[root@python ~]# htpasswd -cb yt yu 123
Adding password for user yu
[root@python ~]# htpasswd -b yt yutre 123qwe
Adding password for user yutre
[root@python ~]# cat yt
yu:$apr1$/N3KI0q8$UxOw8KlG1QBO5N2Niryxo0
yutre:$apr1$BAFJsGn2$qKrWI0G6cSzPPIEG4XGPV0

  nginx配置

[root@python vhast]# cat auth_basic.conf
server {
server_name auth_basic.com;
default_type text/plain;
root html/;
location /{
satisfy any;
auth_basic "tset auth_basic";
auth_basic_user_file passwd;
deny all;
}
}

  auth_request模块 基于第三方库做认证;需要重新编译,默认没有这个模块;

[root@python vhast]# cd ~/nginx-1.15.9/
[root@python nginx-1.15.9]# ./configure --prefix=/data/web --sbin-path=/usr/bin --user=nginx --group=nginx --with-http_stub_status_module --with-http_auth_request_module
checking for OS
[root@python nginx-1.15.9]# make
[root@python nginx-1.15.9]# rm -rf /usr/bin/nginx
[root@python nginx-1.15.9]# cp objs/nginx /usr/bin/

  原理:收到请求后,生成子请求,通过反向代理技术把请求传递给上游服务器,通过上游服务的响应来判断是否处理这个请求,若上游服务器返回的响应码是2**,则继续执行,若返回401或403;则将响应码返回客户端

指令介绍

Syntax: auth_request uri | off;
Default: auth_request off;
Context: http, server, location
Syntax: auth_request_set $variable value;
Default: —
Context: http, server, location

  配置

server {
server_name auth_basic.com;
root html;
location /iiiii{
satisfy any;
auth_basic "tset auth_basic";
auth_basic_user_file passwd;
deny all;
}
location / {
auth_request /test_auth;
}
location = /test_auth {
proxy_pass http://127.0.0.1:90;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
}
} 认证服务器
server {
listen 90;
location / {
return 201 'auth succes';
}
}

  测试正常返回

测试异常返回

[root@python vhast]# cat test-l.conf
server {
listen 90;
location / {
return 401 'auth succes';
}
}

  测试

satisfy指令介绍

Syntax: satisfy all | any;  #all表示3个模块都通过认证才往下走;any表示3个模块任意一个通过就可以通过了
Default: satisfy all;
Context: http, server, location

  

有return指令,access阶段的指令不会生效

nginx的access的阶段的access模块、auth_basic模块、auth_request模块及satisfy指令介绍的更多相关文章

  1. Nginx 服务器伪静态配置不当造成 Access denied

    Nginx 服务器伪静态配置不当造成 Access denied 有群有反馈将 FastAdmin 布署到阿里云后无法打开后台. 出现如下提示,首页是可以打开,点登录链接后出现的.(下是群友的截图) ...

  2. Nginx基于TCP/UDP端口的四层负载均衡(stream模块)配置梳理

    通过我们会用Nginx的upstream做基于http/https端口的7层负载均衡,由于Nginx老版本不支持tcp协议,所以基于tcp/udp端口的四层负载均衡一般用LVS或Haproxy来做.至 ...

  3. 使用auth_request模块实现nginx端鉴权控制

    使用auth_request模块实现nginx端鉴权控制 nginx-auth-request-module 该模块是nginx一个安装模块,使用配置都比较简单,只要作用是实现权限控制拦截作用.默认高 ...

  4. nginx日志模块与HTTP过滤模块与sub模块修改返回内容

    日志格式使用指令 指令介绍 Syntax: log_format name [escape=default|json|none] string ...; Default: log_format com ...

  5. nginx 11个处理阶段 && nginx lua 8个处理阶段

    1. nginx 11 个处理阶段 nginx实际把请求处理流程划分为了11个阶段,这样划分的原因是将请求的执行逻辑细分,各阶段按照处理时机定义了清晰的执行语义,开发者可以很容易分辨自己需要开发的模块 ...

  6. 原已经安装好的nginx,现在需要添加一个未被编译安装的模块--echo-nginx-module-0.56

    为了测试一个NGINX变量,将NGINX加了一个编译模板echo-nginx-module-0.56. 参照如下文件 1,先看以前NGINX有哪些东东. sbin/nginx -Vnginx vers ...

  7. Access之C#连接Access

    原文:Access之C#连接Access 如果是个人用的小程序的话.一般都推荐用Sqlite和Access 使用SQlite数据库需要安装SQLite驱动,详情:SQLite之C#连接SQLite 同 ...

  8. nginx防盗链处理模块referer和secure_link模块

    使用场景:某网站听过URI引用你的页面:当用户在网站点击url时:http头部会通过referer头部,将该网站当前页面的url带上,告诉服务本次请求是由这个页面发起的 思路:通过referer模块, ...

  9. Day5 模块及Python常用模块

    模块概述 定义:模块,用一砣代码实现了某类功能的代码集合. 为了编写可维护的代码,我们把很多函数分组,分别放到不同的文件里,提供了代码的重用性.在Python中,一个.py文件就称之为一个模块(Mod ...

随机推荐

  1. VUE style 绑定

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. halo的工作目录,有一个是在代码里配置的,硬编码了

    在HaloProperties.java中: /** * Work directory. */private String workDir = HaloConst.USER_HOME + " ...

  3. linux shell 正则表达式详解

    正则 1. 普通正则表达式 2. 扩展正则表达式 普通正则表达式 . 任意一个字符 * 前面一个字符出现0次或者多次 [abc] 中括号内任意一个字符 [^abc] 非括号内任意一个字符 [0-9] ...

  4. 每天进步一点点------DE2-70-TV例子说明

    module Reset_Delay(iCLK,iRST,oRST_0,oRST_1,oRST_2); input iCLK; input iRST; output reg oRST_0; outpu ...

  5. 忽视自身问题并“积极甩锅”,新氧CEO金星还要脸吗?

    编辑 | 于斌 出品 | 于见(mpyujian) "互联网医美第一股"新氧果然还是爆雷了. 说"果然"是因为于见曾经针对新氧目前的商业模式进行过分析,认为以新 ...

  6. blog主题——樱花

    贮存一下,blog代码 QAQ 页脚html <!--live2d--> <script src="https://blog-static.cnblogs.com/file ...

  7. python操作oracle完整教程

    1.    连接对象 操作数据库之前,首先要建立数据库连接.有下面几个方法进行连接. >>>import cx_Oracle>>>db = cx_Oracle.co ...

  8. bootstrap创建带遮罩层的进度条

    <div class="modal fade" id="loadingModal"> <div style="width: 200p ...

  9. 读书笔记 - 把时间当作朋友 by 李笑来

    要管理的不是时间,而是自己. 摸着石头渐行渐远,最终也能过河.- 朱敏 赛伯乐(中国)投资公司 董事长 一切都靠积累,一切都可提前准备,越早醒悟越好.人的一生是奋斗的一生,但是有的人一生过得很伟大,有 ...

  10. 【C语言】创建一个函数,利用该函数将字符串中的小写字母转换为大写字母

    原理: 这类题目主要通过ASCII(美国信息交换标准代码)码差值实现,A对应ASCII码十进制数字是65,a对应ASCII码十进制数字是97,即大小写字母之间ASCII码差值为32,想要将大写字母转换 ...