nginx lua api translation
The Nginx api for lua mentioned here refers to the nginx.conf file Use the *_by_lua and *_by_lua_file instructions to use lua code to provide specialized APIs for lua.
syntax:val = ngx.arg[index]
context: set_by_lua*, body_filter_by_lua*
By using valua = ngx.arg[n] , let nginx variables be passed into lua as parameters to call lua. The usage method is as follows: the value of<span>location</span> /foo <span>{</span><span>set</span><span>$a</span><span>32</span><span>;</span><span>set</span><span>$b</span><span>56</span><span>;</span> set_by_lua <span>$sum</span><span>'return tonumber(ngx.arg[1]) + tonumber(ngx.arg[2])'</span><span>$a</span><span>$b</span><span>;</span> echo <span>$sum</span><span>;</span><span>}</span>
syntax:ngx.var.VAR_NAME
context: set_by_lua*, rewrite_by_lua*, access _by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua* , log_by_lua*You can read and write nginx variables through the following code
value = ngx.var.some_nginx_variable_namengx.var.some_nginx_variable_name=value
<span>location</span> /foo <span>{</span><span>set</span><span>$my_var</span><span>''</span><span>;</span><span><em># this line is required to create $my_var at config time</em></span> content_by_lua <span>' ngx.var.my_var = 123; ... '</span><span>;</span><span>}</span>
context:init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua, *log_by_lua*, ngx.timer.*Some core constants
ngx.OK <span>(</span><span>0</span><span>)</span> ngx.ERROR <span>(</span>-<span>1</span><span>)</span> ngx.AGAIN <span>(</span>-<span>2</span><span>)</span> ngx.DONE <span>(</span>-<span>4</span><span>)</span> ngx.DECLINED <span>(</span>-<span>5</span><span>)</span>
context: init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua, log_by_lua*, ngx.timer.*
ngx.HTTP_GET ngx.HTTP_HEAD ngx.HTTP_PUT ngx.HTTP_POST ngx.HTTP_DELETE ngx.HTTP_OPTIONS (added in the v0.5.0rc24 release) ngx.HTTP_MKCOL (added in the v0.8.2 release) ngx.HTTP_COPY (added in the v0.8.2 release) ngx.HTTP_MOVE (added in the v0.8.2 release) ngx.HTTP_PROPFIND (added in the v0.8.2 release) ngx.HTTP_PROPPATCH (added in the v0.8.2 release) ngx.HTTP_LOCK (added in the v0.8.2 release) ngx.HTTP_UNLOCK (added in the v0.8.2 release) ngx.HTTP_PATCH (added in the v0.8.2 release) ngx.HTTP_TRACE (added in the v0.8.2 release)
context:init_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua, log_by_lua*, ngx.timer.*
value <span>=</span> ngx.HTTP_OK <span>(</span><span>200</span><span>)</span> value <span>=</span> ngx.HTTP_CREATED <span>(</span><span>201</span><span>)</span> value <span>=</span> ngx.HTTP_SPECIAL_RESPONSE <span>(</span><span>300</span><span>)</span> value <span>=</span> ngx.HTTP_MOVED_PERMANENTLY <span>(</span><span>301</span><span>)</span> value <span>=</span> ngx.HTTP_MOVED_TEMPORARILY <span>(</span><span>302</span><span>)</span> value <span>=</span> ngx.HTTP_SEE_OTHER <span>(</span><span>303</span><span>)</span> value <span>=</span> ngx.HTTP_NOT_MODIFIED <span>(</span><span>304</span><span>)</span> value <span>=</span> ngx.HTTP_BAD_REQUEST <span>(</span><span>400</span><span>)</span> value <span>=</span> ngx.HTTP_UNAUTHORIZED <span>(</span><span>401</span><span>)</span> value <span>=</span> ngx.HTTP_FORBIDDEN <span>(</span><span>403</span><span>)</span> value <span>=</span> ngx.HTTP_NOT_FOUND <span>(</span><span>404</span><span>)</span> value <span>=</span> ngx.HTTP_NOT_ALLOWED <span>(</span><span>405</span><span>)</span> value <span>=</span> ngx.HTTP_GONE <span>(</span><span>410</span><span>)</span> value <span>=</span> ngx.HTTP_INTERNAL_SERVER_ERROR <span>(</span><span>500</span><span>)</span> value <span>=</span> ngx.HTTP_METHOD_NOT_IMPLEMENTED <span>(</span><span>501</span><span>)</span> value <span>=</span> ngx.HTTP_SERVICE_UNAVAILABLE <span>(</span><span>503</span><span>)</span> value <span>=</span> ngx.HTTP_GATEWAY_TIMEOUT <span>(</span><span>504</span><span>)</span><span>(</span>first added in the v0.3.1rc38 release<span>)</span>
context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua, log_by_lua*, ngx.timer.*
Some level constants of
ngx.STDERR ngx.EMERG ngx.ALERT ngx.CRIT ngx.ERR ngx.WARN ngx.NOTICE ngx.INFO ngx.DEBUG
syntax: print(...)
context:init_by_lua*, init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua, log_by_lua*, ngx.timer.*This API uses the log level of ngx.NOTICE to write the parameter value into the error.log file, which is equivalent to ngx.log(ngx.NOTICE,...)
context:init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua, log_by_lua*, ngx.timer.*
ngx.ctx.xxx xxx is any variable name, ngx.ctx can be regarded as a temporary dictionary, The scope is each request, which means that different requests have different ngx.ctxAs in the example below
<span>location</span> /test <span>{</span> rewrite_by_lua <span>' ngx.say("foo = ", ngx.ctx.foo) ngx.ctx.foo = 76 '</span><span>;</span> access_by_lua <span>' ngx.ctx.foo = ngx.ctx.foo + 3 '</span><span>;</span> content_by_lua <span>' ngx.say(ngx.ctx.foo) '</span><span>;</span><span>}</span>
foo = nil <span>79</span>
Look at the example below again
<span>location</span> /sub <span>{</span> content_by_lua <span>' ngx.say("sub pre: ", ngx.ctx.blah) ngx.ctx.blah = 32 ngx.say("sub post: ", ngx.ctx.blah) '</span><span>;</span><span>}</span> <span>location</span> /main <span>{</span> content_by_lua <span>' ngx.ctx.blah = 73 ngx.say("main pre: ", ngx.ctx.blah) local res = ngx.location.capture("/sub") ngx.print(res.body) ngx.say("main post: ", ngx.ctx.blah) '</span><span>;</span><span>}</span>
main pre: <span>73</span> sub pre: nil sub post: <span>32</span> main post: <span>73</span>
In addition, in the init_worker_by_lua instruction, we can initialize ngx.ctx in the form of a dictionary
ngx.ctx = {foo = 32, bar = 54}
syntax: res = ngx.location.capture(uri, options?)
context: rewrite_by_lua*, access_by_lua*, content_by_lua*通过这个api,lua可以访问本server的其他location,只能是同一个server的。用法如下
res <span>=</span> ngx.location.capture<span>(</span>uri<span>)</span>
-capture函数除了url还有其他参数可以选择,包括
-method 设置访问的method类型
-body 设置访问子请求的httpbody内容
-args设置请求的参数
ngx.location.capture<span>(</span><span>'/foo?a=1'</span>, <span>{</span> args <span>=</span><span>{</span> b <span>=</span><span>3</span>, c <span>=</span><span>':'</span><span>}</span><span>}</span><span>)</span>
ngx.location.capture<span>(</span><span>'/foo?a=1&b=3&c=%3a'</span><span>)</span>
<span>location</span> /sub <span>{</span> content_by_lua <span>' ngx.ctx.foo = "bar"; '</span><span>;</span><span>}</span><span>location</span> /lua <span>{</span> content_by_lua <span>' local ctx = {} res = ngx.location.capture("/sub", { ctx = ctx }) ngx.say(ctx.foo); ngx.say(ngx.ctx.foo); '</span><span>;</span><span>}</span>
结果如下,仅仅是设置ctx这个字典的值,而不是共享ngx.ctx
bar nil
<span>location</span> /other <span>{</span> content_by_lua <span>' ngx.say("dog = ", ngx.var.dog) ngx.say("cat = ", ngx.var.cat) '</span><span>;</span><span>}</span> <span>location</span> /lua <span>{</span><span>set</span><span>$dog</span><span>''</span><span>;</span><span>set</span><span>$cat</span><span>''</span><span>;</span> content_by_lua <span>' res = ngx.location.capture("/other", { vars = { dog = "hello", cat = 32 }}); ngx.print(res.body) '</span><span>;</span><span>}</span>
dog = hello cat = 32
<span>location</span> /other <span>{</span><span>set</span><span>$dog</span><span>"$dog world"</span><span>;</span> echo <span>"$uri dog: $dog"</span><span>;</span><span>}</span> <span>location</span> /lua <span>{</span><span>set</span><span>$dog</span><span>'hello'</span><span>;</span> content_by_lua <span>' res = ngx.location.capture("/other", { copy_all_vars = true }); ngx.print(res.body) ngx.say(ngx.var.uri, ": ", ngx.var.dog) '</span><span>;</span><span>}</span>
/other dog: hello world /lua: hello
<span>location</span> /other <span>{</span><span>set</span><span>$dog</span><span>"$dog world"</span><span>;</span> echo <span>"$uri dog: $dog"</span><span>;</span><span>}</span> <span>location</span> /lua <span>{</span><span>set</span><span>$dog</span><span>'hello'</span><span>;</span> content_by_lua <span>' res = ngx.location.capture("/other", { share_all_vars = true }); ngx.print(res.body) ngx.say(ngx.var.uri, ": ", ngx.var.dog) '</span><span>;</span><span>}</span>
/other dog: hello world /lua: hello world
-always_forward_body 如果body属性没有设置,这个属性设置为true,那将发送父请求的httpbody给子请求。
syntax: res1, res2, ... = ngx.location.capture_multi({ {uri, options?}, {uri, options?}, ... })
context: rewrite_by_lua*, access_by_lua*, content_by_lua*
类似于上面的ngx.location.capture ,不过支持并行请求多个子请求res1, res2, res3 <span>=</span> ngx.location.capture_multi<span>{</span><span>{</span><span>"/foo"</span>, <span>{</span> args <span>=</span><span>"a=3&b=4"</span><span>}</span><span>}</span>, <span>{</span><span>"/bar"</span><span>}</span>, <span>{</span><span>"/baz"</span>, <span>{</span> method <span>=</span> ngx.HTTP_POST, body <span>=</span><span>"hello"</span><span>}</span><span>}</span>, <span>}</span> <span>if</span> res1.status <span>==</span> ngx.HTTP_OK <span>then</span> ... <span>end</span> <span>if</span> res2.body <span>==</span><span>"BLAH"</span><span>then</span> ... <span>end</span>
<span><em>-- construct the requests table</em></span><span>local</span> reqs <span>=</span><span>{</span><span>}</span><span>table.insert</span><span>(</span>reqs, <span>{</span><span>"/mysql"</span><span>}</span><span>)</span><span>table.insert</span><span>(</span>reqs, <span>{</span><span>"/postgres"</span><span>}</span><span>)</span><span>table.insert</span><span>(</span>reqs, <span>{</span><span>"/redis"</span><span>}</span><span>)</span><span>table.insert</span><span>(</span>reqs, <span>{</span><span>"/memcached"</span><span>}</span><span>)</span> <span><em>-- issue all the requests at once and wait until they all return</em></span><span>local</span> resps <span>=</span><span>{</span> ngx.location.capture_multi<span>(</span>reqs<span>)</span><span>}</span> <span><em>-- loop over the responses table</em></span><span>for</span> i, resp <span>in</span><span>ipairs</span><span>(</span>resps<span>)</span><span>do</span><span><em>-- process the response table "resp"</em></span><span>end</span>
context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua, log_by_lua*
读取或者设置当前的请求响应状态,这个应该在发送内容给浏览器之前执行
ngx.status <span>=</span> ngx.HTTP_CREATED status <span>=</span> ngx.status
syntax: ngx.header.HEADER = VALUE
syntax: value = ngx.header.HEADER
context: rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua, log_by_lua*
获取或者设置http header的值<span><em>-- equivalent to ngx.header["Content-Type"] = 'text/plain'</em></span> ngx.header.content_type <span>=</span><span>'text/plain'</span><span>;</span> ngx.header<span>[</span><span>"X-My-Header"</span><span>]</span><span>=</span><span>'blah blah'</span><span>;</span>
ngx.header<span>[</span><span>'Set-Cookie'</span><span>]</span><span>=</span><span>{</span><span>'a=32; path=/'</span>, <span>'b=4; path=/'</span><span>}</span>
Set-Cookie: <span>a</span>=<span>32</span>; <span>path</span>=<span>/</span> Set-Cookie: <span>b</span>=<span>4</span>; <span>path</span>=<span>/</span>
<span>location</span> /test <span>{</span><span>set</span><span>$footer</span><span>''</span><span>;</span> <span>proxy_pass</span><span>http</span>://some-backend<span>;</span> header_filter_by_lua <span>' if ngx.header["X-My-Header"] == "blah" then ngx.var.footer = "some value" end '</span><span>;</span> echo_after_body <span>$footer</span><span>;</span><span>}</span>
syntax: headers = ngx.resp.get_headers(max_headers?, raw?)
context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua, log_by_lua*
<span>local</span> h <span>=</span> ngx.resp.get_headers<span>(</span><span>)</span><span>for</span> k, v <span>in</span><span>pairs</span><span>(</span>h<span>)</span><span>do</span> ... <span>end</span>
syntax: secs = ngx.req.start_time()
context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*
<span>local</span> request_time <span>=</span> ngx.now<span>(</span><span>)</span> - ngx.req.start_time<span>(</span><span>)</span>
syntax: num = ngx.req.http_version()
context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*
获取请求的http versionsyntax: str = ngx.req.raw_header(no_request_line?)
context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*
得到原http header的字符串文本内容ngx.<span>print</span><span>(</span>ngx.req.raw_header<span>(</span><span>)</span><span>)</span>
GET /t HTTP/1.1 Host: localhost Connection: close Foo: bar
syntax: method_name = ngx.req.get_method()
context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*
获得当前请求的method 名字syntax: ngx.req.set_method(method_id)
context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*
设置覆盖此次请求的method名字syntax: ngx.req.set_uri(uri, jump?)
context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*
作用与rewrite相同,其中jump默认为false,false的时候ngx.req.set_uri<span>(</span><span>"/foo"</span>, <span>false</span><span>)</span>
<span>rewrite</span> ^ /foo <span>break</span><span>;</span>
ngx.req.set_uri<span>(</span><span>"/foo"</span>, <span>true</span><span>)</span>
<span>rewrite</span> ^ /foo last<span>;</span>
syntax: ngx.req.set_uri_args(args)
context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*
rewrite当前的请求参数ngx.req.set_uri_args<span>(</span><span>"a=3&b=hello%20world"</span><span>)</span>
ngx.req.set_uri_args<span>(</span><span>{</span> a <span>=</span><span>3</span>, b <span>=</span><span>"hello world"</span><span>}</span><span>)</span>
syntax: args = ngx.req.get_uri_args(max_args?)
context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua, log_by_lua*
获得请求的参数<span>location</span><span>=</span> /test <span>{</span> content_by_lua <span>' local args = ngx.req.get_uri_args() for key, val in pairs(args) do if type(val) == "table" then ngx.say(key, ": ", table.concat(val, ", ")) else ngx.say(key, ": ", val) end end '</span><span>;</span><span>}</span>
foo: bar bar: baz, blah
syntax: args, err = ngx.req.get_post_args(max_args?)
context: rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua, log_by_lua*
得到post提交的参数<span>location</span><span>=</span> /test <span>{</span> content_by_lua <span>' ngx.req.read_body() local args, err = ngx.req.get_post_args() if not args then ngx.say("failed to get post args: ", err) return end for key, val in pairs(args) do if type(val) == "table" then ngx.say(key, ": ", table.concat(val, ", ")) else ngx.say(key, ": ", val) end end '</span><span>;</span><span>}</span>
<span><em># Post request with the body 'foo=bar&bar=baz&bar=blah'</em></span> $ curl <span>--data</span><span>'foo=bar&bar=baz&bar=blah'</span> localhost<span>/</span><span>test</span>
foo: bar bar: baz, blah
syntax: headers = ngx.req.get_headers(max_headers?, raw?)
context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua, log_by_lua*
获取当前请求的头信息<span>local</span> h <span>=</span> ngx.req.get_headers<span>(</span><span>)</span><span>for</span> k, v <span>in</span><span>pairs</span><span>(</span>h<span>)</span><span>do</span> ... <span>end</span>
ngx.say<span>(</span><span>"Host: "</span>, ngx.req.get_headers<span>(</span><span>)</span><span>[</span><span>"Host"</span><span>]</span><span>)</span>
syntax: ngx.req.set_header(header_name, header_value)
context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua
设置当前的请求头ngx.req.set_header<span>(</span><span>"Content-Type"</span>, <span>"text/css"</span><span>)</span>
ngx.req.set_header<span>(</span><span>"Foo"</span>, <span>{</span><span>"a"</span>, <span>"abc"</span><span>}</span><span>)</span>
syntax: ngx.req.clear_header(header_name)
context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*
清除某一个请求头syntax: ngx.req.read_body()
context: rewrite_by_lua*, access_by_lua*, content_by_lua*
在不阻塞nginx事件轮询的情况下读取客户端请求的bodyngx.req.read_body<span>(</span><span>)</span><span>local</span> args <span>=</span> ngx.req.get_post_args<span>(</span><span>)</span>
syntax: ngx.req.discard_body()
context: rewrite_by_lua*, access_by_lua*, content_by_lua*
明确丢弃客户端请求bodysyntax: data = ngx.req.get_body_data()
context: rewrite_by_lua*, access_by_lua*, content_by_lua*
以字符串的形式获得客户端的请求body内容syntax: file_name = ngx.req.get_body_file()
context: rewrite_by_lua*, access_by_lua*, content_by_lua*
当发送文件请求的时候,获得文件的名字syntax: ngx.req.set_body_data(data)
context: rewrite_by_lua*, access_by_lua*, content_by_lua*
设置客户端请求的bodysyntax: ngx.req.set_body_data(data)
context: rewrite_by_lua*, access_by_lua*, content_by_lua*
通过filename来指定当前请求的file data。syntax: ngx.req.init_body(buffer_size?)
context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*
创建一个当前请求的空白body的buffer,后续可以自己写入请求的body。ngx.req.init_body<span>(</span><span>128</span><span>*</span><span>1024</span><span>)</span><span><em>-- buffer is 128KB</em></span><span>for</span> chunk <span>in</span> next_data_chunk<span>(</span><span>)</span><span> do</span> ngx.req.append_body<span>(</span>chunk<span>)</span><span><em>-- each chunk can be 4KB</em></span><span>end</span> ngx.req.finish_body<span>(</span><span>)</span>
syntax: ngx.req.append_body(data_chunk)
context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*
追加当前请求的http bodysyntax: ngx.req.finish_body()
context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*
标志完成ngx.req.init_body的数据追加。syntax: tcpsock, err = ngx.req.socket()
syntax: tcpsock, err = ngx.req.socket(raw)
context: rewrite_by_lua*, access_by_lua*, content_by_lua*
这个方法会返回一个只读的cosocket对象,用来读取当前请求的request http body内容。syntax: ngx.exec(uri, args?)
context: rewrite_by_lua*, access_by_lua*, content_by_lua*
执行内部跳转根据url和请求参数ngx.exec<span>(</span><span>'/some-location'</span><span>)</span><span>;</span> ngx.exec<span>(</span><span>'/some-location'</span>, <span>'a=3&b=5&c=6'</span><span>)</span><span>;</span> ngx.exec<span>(</span><span>'/some-location?a=3&b=5'</span>, <span>'c=6'</span><span>)</span><span>;</span>
<span>location</span> /foo <span>{</span> content_by_lua <span>' ngx.exec("@bar", "a=goodbye"); '</span><span>;</span><span>}</span> <span>location</span><span>@bar</span><span>{</span> content_by_lua <span>' local args = ngx.req.get_uri_args() for key, val in pairs(args) do if key == "a" then ngx.say(val) end end '</span><span>;</span><span>}</span>
syntax: ngx.redirect(uri, status?)
context: rewrite_by_lua*, access_by_lua*, content_by_lua*
执行301或者302的重定向。syntax: ok, err = ngx.send_headers()
context: rewrite_by_lua*, access_by_lua*, content_by_lua*
指定响应头。syntax: value = ngx.headers_sent
context: set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*
判断头部是否发送给客户端了。syntax: ok, err = ngx.print(...)
context: rewrite_by_lua*, access_by_lua*, content_by_lua*
发送数据给客户端响应页面<span>local</span><span>table</span><span>=</span><span>{</span><span>"hello, "</span>, <span>{</span><span>"world: "</span>, <span>true</span>, <span>" or "</span>, <span>false</span>, <span>{</span><span>": "</span>, <span>nil</span><span>}</span><span>}</span><span>}</span> ngx.<span>print</span><span>(</span><span>table</span><span>)</span>
syntax: ok, err = ngx.say(...)
context: rewrite_by_lua*, access_by_lua*, content_by_lua*
作用类似于ngx.printsyntax: ngx.log(log_level, ...)
context: init_by_lua*, init_worker_by_lua*, set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*, ngx.timer.*
向error.log中记录日志syntax: ok, err = ngx.flush(wait?)
context: rewrite_by_lua*, access_by_lua*, content_by_lua*
将flush内容到客户端页面syntax: ngx.exit(status)
context: rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, ngx.timer.*
ngx.status <span>=</span> ngx.HTTP_GONE ngx.say<span>(</span><span>"This is our own content"</span><span>)</span><span><em>-- to cause quit the whole request rather than the current phase handler</em></span> ngx.<span>exit</span><span>(</span>ngx.HTTP_OK<span>)</span>
当status==0的时候,跳过此次代码片段,并且继续执行下面的。
syntax: ok, err = ngx.eof()
context: rewrite_by_lua*, access_by_lua*, content_by_lua*
<span>location</span><span>=</span> /async <span>{</span><span>keepalive_timeout</span><span>0</span><span>;</span> content_by_lua <span>' ngx.say("got the task!") ngx.eof() -- a descent HTTP client will close the connection at this point -- access MySQL, PostgreSQL, Redis, Memcached, and etc here... '</span><span>;</span><span>}</span>
以上就介绍了nginx lua api翻译,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics





The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

To get Nginx to run Apache, you need to: 1. Install Nginx and Apache; 2. Configure the Nginx agent; 3. Start Nginx and Apache; 4. Test the configuration to ensure that you can see Apache content after accessing the domain name. In addition, you need to pay attention to other matters such as port number matching, virtual host configuration, and SSL/TLS settings.
