Skip to content

Latest commit

 

History

History
45 lines (26 loc) · 2.48 KB

set_by_lua_file.md

File metadata and controls

45 lines (26 loc) · 2.48 KB

set_by_lua_file

syntax: set_by_lua_file $res <path-to-lua-script-file> [$arg1 $arg2 ...]

context: server, server if, location, location if

phase: rewrite

除了通过文件<path-to-lua-script-file>的内容指定 Lua 代码外,该指令与set_by_lua是等价的,该指令从v0.5.0rc32开始支持Lua/LuaJIT bytecode的执行。

对于该指令,对<path-to-lua-script-file>的字符串参数支持内联 Nginx 变量。但必须要额外注意注入攻击。

当给定了一个相对路径如foo/bar.lua,它将会被转换成绝对路径,前面增加的部分路径是 Nginx 服务启动时通过命令行选项-p PATH决定的server prefix

当 Lua 代码缓存开启(默认),用户代码在第一次请求时完成加载(只有一次)并缓存,当 Lua 文件被修改时,每次都要对 Nginx 配置进行重新加载。Lua 代码缓存是可以暂时被禁用,通过开关lua_code_cachenginx.conf中设置为off,这样就可以避免反复重新加载 Nginx。

该指令需要 ngx_devel_kit 模块。

返回目录

English source:

set_by_lua_file

syntax: set_by_lua_file $res <path-to-lua-script-file> [$arg1 $arg2 ...]

context: server, server if, location, location if

phase: rewrite

Equivalent to set_by_lua, except that the file specified by <path-to-lua-script-file> contains the Lua code, or, as from the v0.5.0rc32 release, the Lua/LuaJIT bytecode to be executed.

Nginx variable interpolation is supported in the <path-to-lua-script-file> argument string of this directive. But special care must be taken for injection attacks.

When a relative path like foo/bar.lua is given, they will be turned into the absolute path relative to the server prefix path determined by the -p PATH command-line option while starting the Nginx server.

When the Lua code cache is turned on (by default), the user code is loaded once at the first request and cached and the Nginx config must be reloaded each time the Lua source file is modified. The Lua code cache can be temporarily disabled during development by switching lua_code_cache off in nginx.conf to avoid reloading Nginx.

This directive requires the ngx_devel_kit module.

Back to TOC