9

Nginx/OpenResty 指令的执行顺序

 2 years ago
source link: https://fann.im/blog/2015/05/21/nginx-phases/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Nginx/OpenResty 指令的执行顺序

May 21, 2015

  1. http, 可以通过 init_by_lua 加载公共函数,比如 lua-resty-core.
  2. server selection,listen,server_name.
  3. post read, ngx_realip.
  4. server rewrite, set, rewrite, return, set_by_lua.
  5. server rewrite tail, rewrite_by_lua.
  6. server access, allow, deny.
  7. server access tail, access_by_lua.
  8. server try_files.
  9. location:
    1. prefix strings 遵循 最长子串匹配原则
    2. regular expressions 遵循 先定义优先匹配原则
    3. location = {exact_url} 精准匹配
    4. location ~ {case-sensitive regex} 区分大小写
    5. location ~* {case-insensitive regex} 不区分大小写
    6. location ^~ {prefix_string_if_any} 一旦字符匹配成功,就不再正则匹配
    7. 尽量不要 if,换用 try_files
    8. -f 检测文件是否存在,-d 目录,-e 文件/目录/符号链接,-x 可执行文件
  10. location rewrite, set, rewrite, return, set_by_lua.
  11. location rewrite tail, rewrite_by_lua.
  12. preaccess, degradation, limit_zone, limit_req, ngx_realip.
  13. location access, allow, deny, auth_basic.
  14. location access tail, access_by_lua.
  15. content, ngx_echo, proxy_pass, content_by_lua.
    1. 请求具体处理阶段,只能有一个 内容处理程序(content handler)
    2. 多个 echo 可以共存,因为同属于 ngx_echo 模块,但 ngx_lua 限制只能有一个 content_by_lua.
    3. ngx_echo 的 echo_before_body/echo_after_body 可以和其他模块共存
    4. 如果没有 ngx_echo, proxy_pass, content_lua 这些 content handler,Nginx 会根据 URL 将请求映射到静态资源服务模块,依次是 ngx_index, ngx_autoindex, ngx_static.
    5. ngx_index/ngx_autoindex 处理以 / 结尾的请求,ngx_static 正好相反。
  16. output header filter, more_set_headers 输出 Headers.
  17. output filter echo_before_body, echo_after_body, body_filter_by_lua.
  18. log, access_log, error_log, log_by_lua.
  19. post action.

OpenResty

Was this page helpful?


Recommend

  • 102

    OpenResty - Turning Nginx into a Full-Fledged Scriptable Web Platform Table of Contents Description OpenResty is a full-fledged web application server by bundling the standard nginx core, lots of 3rd-party nginx modules,...

  • 91

    404 页面不存在 404. 抱歉,您访问的资源不存在。 可能是网址有误,或者对应的内容被删除,或者处于私有状态。 代码改变世界,联系邮箱 [email protected]

  • 82

    原题首先来看看这道题:123456789101112131415161718public class test1 { static String s = "A"; public static void main(String[] args) {

  • 37
    • www.hongweipeng.com 6 years ago
    • Cache

    js异步加载顺序执行

    前言 前端优化有个原则,叫资源懒加载。 对于某些js资源,我们在页面load前并不需要用到,加载反而会影响到首屏速度。 把这些js放到 load 后进行加载,我们称之为js异步加载。 异步加载的手段

  • 44
    • www.cnblogs.com 6 years ago
    • Cache

    Django中间件执行顺序

    中间件 Django中的中间件是一个轻量级、底层的插件系统,可以介入Django的请求和响应处理过程,修改Django的输入或输出。中间件的设计为开发者提供了一种无侵入式的开发方式,增强了Django框架的健壮性。 我们可以使...

  • 57
    • www.tuicool.com 5 years ago
    • Cache

    MySQL执行过程以及顺序

    前言:MySQL在我们的开发中基本每天都要面对的,作为开发中的数据中间件,MySQL承担者存储数据和读写数据的职责。因为学习和了解MySQL是至关重要的,那么当我们在客户端发起一个sql到出现详细的查询数据,这其中究竟经历了什么样的过程?MySQL服务端是...

  • 6
    • www.wencst.com 4 years ago
    • Cache

    nginx的location匹配规则和顺序

    nginx的location匹配规则和顺序 作者: wencst 分类: linux,架构设计

  • 6

    通过Nginx(OpenResty)修改UserAgent - 干雨 - 博客园 其实我是一个程序员 ...

  • 5
    • blog.51cto.com 2 years ago
    • Cache

    nginx开发头文件的包含顺序

    nginx开发头文件的包含顺序 原创 北京王老师 2022-08-02 16:53:07

  • 9
    • abcdxyzk.github.io 2 years ago
    • Cache

    Nginx Openresty - 读取请求体

    Nginx Openresty - 读取请求体 2022-10-30 15:33:00

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK