网站首页 > 基础教程 正文
init_by_lua http
set_by_lua server, server if, location, location if rewrite_by_lua
http, server, location, location if access_by_lua http, server,
location, location if content_by_lua location, location if
header_filter_by_lua http, server, location, location if
body_filter_by_lua http, server, location, location if log_by_lua
http, server, location, location if init_by_lua:
在nginx重新加载配置文件时,运行里面lua脚本,常用于全局变量的申请。
例如lua_shared_dict共享内存的申请,只有当nginx重起后,共享内存数据才清空,这常用于统计。 set_by_lua:
设置一个变量,常用与计算一个逻辑,然后返回结果 该阶段不能运行Output API、Control API、Subrequest
API、Cosocket API rewrite_by_lua: 在access阶段前运行,主要用于rewrite
access_by_lua: 主要用于访问控制,能收集到大部分变量,类似status需要在log阶段才有。 这条指令运行于nginx
access阶段的末尾,因此总是在 allow 和 deny 这样的指令之后运行,虽然它们同属 access 阶段。
content_by_lua:
阶段是所有请求处理阶段中最为重要的一个,运行在这个阶段的配置指令一般都肩负着生成内容(content)并输出HTTP响应。
header_filter_by_lua: 一般只用于设置Cookie和Headers等 该阶段不能运行Output
API、Control API、Subrequest API、Cosocket API body_filter_by_lua:
一般会在一次请求中被调用多次, 因为这是实现基于 HTTP 1.1 chunked 编码的所谓“流式输出”的。
该阶段不能运行Output API、Control API、Subrequest API、Cosocket API
log_by_lua:
该阶段总是运行在请求结束的时候,用于请求的后续操作,如在共享内存中进行统计数据,如果要高精确的数据统计,应该使用body_filter_by_lua。
该阶段不能运行Output API、Control API、Subrequest API、Cosocket API Nginx顺序
Nginx 处理每一个用户请求时,都是按照若干个不同阶段(phase)依次处理的,而不是根据配置文件上的顺序。 Nginx
处理请求的过程一共划分为 11 个阶段,按照执行顺序依次是
post-read、server-rewrite、find-config、rewrite、post-rewrite、
preaccess、access、post-access、try-files、content、log. post-read:
读取请求内容阶段 Nginx读取并解析完请求头之后就立即开始运行 例如模块 ngx_realip 就在 post-read
阶段注册了处理程序,它的功能是迫使 Nginx 认为当前请求的来源地址是指定的某一个请求头的值。 server-rewrite
Server请求地址重写阶段 当 ngx_rewrite 模块的set配置指令直接书写在 server 配置块中时,基本上都是运行在
server-rewrite 阶段 find-config 配置查找阶段 这个阶段并不支持 Nginx 模块注册处理程序,而是由
Nginx 核心来完成当前请求与 location 配置块之间的配对工作。 rewrite Location请求地址重写阶段 当
ngx_rewrite 模块的指令用于 location 块中时,便是运行在这个 rewrite 阶段。
另外,ngx_set_misc(设置md5、encode_base64等) 模块的指令,还有 ngx_lua 模块的
set_by_lua 指令和 rewrite_by_lua 指令也在此阶段。 post-rewrite 请求地址重写提交阶段 由
Nginx 核心完成 rewrite 阶段所要求的“内部跳转”操作,如果 rewrite 阶段有此要求的话。 preaccess
访问权限检查准备阶段 标准模块 ngx_limit_req 和 ngx_limit_zone
就运行在此阶段,前者可以控制请求的访问频度,而后者可以限制访问的并发度。 access 访问权限检查阶段 标准模块
ngx_access、第三方模块 ngx_auth_request 以及第三方模块 ngx_lua 的 access_by_lua
指令就运行在这个阶段。 配置指令多是执行访问控制性质的任务,比如检查用户的访问权限,检查用户的来源 IP 地址是否合法
post-access 访问权限检查提交阶段 主要用于配合 access 阶段实现标准 ngx_http_core 模块提供的配置指令
satisfy 的功能。 satisfy all(与关系) satisfy any(或关系) try-files
配置项try_files处理阶段 专门用于实现标准配置指令 try_files 的功能 如果前 N-1
个参数所对应的文件系统对象都不存在,try-files 阶段就会立即发起“内部跳转”到最后一个参数(即第 N 个参数)所指定的
URI. content 内容产生阶段 Nginx 的 content
阶段是所有请求处理阶段中最为重要的一个,因为运行在这个阶段的配置指令一般都肩负着生成“内容” 并输出 HTTP 响应的使命。
- 上一篇: Lua 面向对象 lua面向对象c模块
- 下一篇: Lua语言在机器人领域的应用入门 机器人语言库
猜你喜欢
- 2024-10-23 按键精灵自动寻路系列换算地图坐标寻路法
- 2024-10-23 [Redis],Lua分步式限流方案,限流分几步?
- 2024-10-23 基于FEKO软件的目标RCS计算及数据分析
- 2024-10-23 [按键精灵]会员时间相关计算/转换的代码讲解
- 2024-10-23 lua math.deg使用 lua的match
- 2024-10-23 梯度下降方法与求导 梯度下降求导过程
- 2024-10-23 redisson实现分布式锁原理 redisson分布式锁问题
- 2024-10-23 万字长文:从源码学习GopherLua与工程实践
- 2024-10-23 LUA入门简易小应用 lua用什么软件编程
- 2024-10-23 lua math.asin使用 lua assert函数
- 05-14CSS基础知识(一) CSS入门
- 05-14CSS是什么? CSS和HTML有什么关系?
- 05-14什么是CSS3?
- 05-14CSS如何画一个三角形?
- 05-14初识CSS——CSS三角制作
- 05-14Wordpress建站教程:给图片添加CSS样式
- 05-14HTML和HTML5,css和css3的区别有哪些?
- 05-14Html中Css样式Ⅱ
- 最近发表
- 标签列表
-
- jsp (69)
- pythonlist (60)
- gitpush (78)
- gitreset (66)
- python字典 (67)
- dockercp (63)
- gitclone命令 (63)
- dockersave (62)
- linux命令大全 (65)
- mysql教程 (60)
- pythonif (86)
- location.href (69)
- deletesql (62)
- c++模板 (62)
- linuxgzip (68)
- 字符串连接 (73)
- nginx配置文件详解 (61)
- html标签 (69)
- c++初始化列表 (64)
- mysqlinnodbmyisam区别 (63)
- arraylistadd (66)
- console.table (62)
- mysqldatesub函数 (63)
- window10java环境变量设置 (66)
- c++虚函数和纯虚函数的区别 (66)