access_by_lua和content_by_lua有什么区别来引用nginx.conf中的lua脚本?

我目前感到困惑。我的代码在每个发送到 location / 的请求中都有效。

########nginx.conf

server {
        listen       8000;
        server_name  localhost;

    lua_code_cache on;

        location / {
            content_by_lua_file /path/to/file.lua;
        }
    }

file.lua 对每个传入的 HTTP 请求执行几个操作。 如果我使用 access_by_lua_file 而不是 content_by_lua_file 来引入 file.lua,它会有什么不同呢?

如果这个问题很蠢,请原谅。请帮助我学习 :)

点赞
用户2858170
用户2858170

access_by_lua_file 作为访问阶段处理器,content_by_lua_file 作为内容阶段处理器。

参考 http://nginx.org/en/docs/dev/development_guide.html#http_phases

NGX_HTTP_ACCESS_PHASE —— 验证客户端是否有权进行请求的阶段。如 ngx_http_access_module 和 ngx_http_auth_basic_module 这样的标准 nginx 模块在此阶段注册它们的处理器。默认情况下,在此阶段注册的所有处理器必须都通过授权检查,才能继续到下一个阶段。satisfy 指令可用于允许处理器授权客户端时,如果任何一个处理器授权该客户端,就允许请求的处理继续进行。

NGX_HTTP_CONTENT_PHASE —— 生成响应的常规阶段。多个标准 nginx 模块在此阶段注册它们的处理器,包括 ngx_http_index_module 或 ngx_http_static_module。它们按顺序调用,直到其中一个模块生成输出。还可以按位置设置内容处理器。如果 ngx_http_core_module 的位置配置设置了处理器,则将其称为内容处理器,并忽略此阶段安装的处理器。

2020-06-04 19:02:26