openresty处理流程梳理
openresty处理流程
openresty有11个处理流程阶段,如下图所示
具体阶段作用域和功能作用如下表
阶段 | 作用域(nginx.conf) | 功能作用 |
init_by_lua* | http | 初始化 nginx 和预加载 lua(nginx 启动和 reload 时执行) |
init_worker_by_lua* | http | 每个工作进程(worker_processes)被创建时执行,用于启动一些定时任务, 比如心跳检查,后端服务的健康检查,定时拉取服务器配置等; |
ssl_certificate_by_lua* | server | 对HTTPS请求的处理 |
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 | 内容处理(WAF规则处理) |
content_by_lua* | location, location if | 内容生成,相当于response |
balancer_by_lua* | upstream | 负载均衡 |
header_filter_by_lua* | http, server, location, location if | 对响应头(headers)进行处理 |
body_filter_by_lua* | http, server, location, location if | 对响应体(body)进行处理 |
log_by_lua* | http, server, location, location if | 日志记录 |