{"id":15407,"date":"2024-11-17T20:56:33","date_gmt":"2024-11-17T12:56:33","guid":{"rendered":"https:\/\/fwq.ai\/blog\/?p=15407"},"modified":"2024-11-17T20:56:33","modified_gmt":"2024-11-17T12:56:33","slug":"openresty%e4%b8%adngx_lua%e6%a8%a1%e5%9d%97%e6%8f%90%e4%be%9b%e7%9a%84%e5%b8%b8%e9%87%8f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/15407\/","title":{"rendered":"openResty\u4e2dngx_lua\u6a21\u5757\u63d0\u4f9b\u7684\u5e38\u91cf"},"content":{"rendered":"<p>ngx_lua\u6a21\u5757\u7684\u539f\u7406\uff1a<\/p>\n<ol>\n<li>\u6bcf\u4e2aworker\uff08\u5de5\u4f5c\u8fdb\u7a0b\uff09\u521b\u5efa\u4e00\u4e2aLua VM\uff0cworker\u5185\u6240\u6709\u534f\u7a0b\u5171\u4eabVM\uff1b<\/li>\n<li>\u5c06Nginx I\/O\u539f\u8bed\u5c01\u88c5\u540e\u6ce8\u5165 Lua VM\uff0c\u5141\u8bb8Lua\u4ee3\u7801\u76f4\u63a5\u8bbf\u95ee\uff1b<\/li>\n<li>\u6bcf\u4e2a\u5916\u90e8\u8bf7\u6c42\u90fd\u7531\u4e00\u4e2aLua\u534f\u7a0b\u5904\u7406\uff0c\u534f\u7a0b\u4e4b\u95f4\u6570\u636e\u9694\u79bb\uff1b<\/li>\n<li>Lua\u4ee3\u7801\u8c03\u7528I\/O\u64cd\u4f5c\u7b49\u5f02\u6b65\u63a5\u53e3\u65f6\uff0c\u4f1a\u6302\u8d77\u5f53\u524d\u534f\u7a0b\uff08\u5e76\u4fdd\u62a4\u4e0a\u4e0b\u6587\u6570\u636e\uff09\uff0c\u800c\u4e0d\u963b\u585eworker\uff1b<\/li>\n<li>I\/O\u7b49\u5f02\u6b65\u64cd\u4f5c\u5b8c\u6210\u65f6\u8fd8\u539f\u76f8\u5173\u534f\u7a0b\u4e0a\u4e0b\u6587\u6570\u636e\uff0c\u5e76\u7ee7\u7eed\u8fd0\u884c<\/li>\n<\/ol>\n<p><strong>\u7cfb\u5217\u6587\u7ae0\uff1a<\/strong><br \/>\n\u6307\u4ee4\uff1aopenResty\u4e2dngx_lua\u6a21\u5757\u63d0\u4f9b\u7684\u6307\u4ee4<br \/>\n\u5e38\u91cf\uff1aopenResty\u4e2dngx_lua\u6a21\u5757\u63d0\u4f9b\u7684\u5e38\u91cf<br \/>\nAPI\uff1aopenResty\u4e2dngx_lua\u6a21\u5757\u63d0\u4f9b\u7684API<\/p>\n<p>&nbsp;<\/p>\n<h1>\u4e8c\u3001\u5e38\u91cf<\/h1>\n<h3><strong>2.1 Core constants<\/strong><\/h3>\n<p><strong>\u4f5c\u7528\u57df:<\/strong>\u00a0<em>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.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*<\/em><\/p>\n<pre>ngx.OK          = 0\r\nngx.ERROR       = -1\r\nngx.AGAIN       = -2\r\nngx.DONE        = -4\r\nngx.DECLINED    = -5\r\nngx.null<\/pre>\n<h3>\u00a02.2 HTTP method constants<\/h3>\n<p><strong>\u4f5c\u7528\u57df:<\/strong>\u00a0<em>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.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*<\/em><\/p>\n<pre>ngx.HTTP_GET        = 2\r\nngx.HTTP_HEAD       = 4\r\nngx.HTTP_POST       = 8\r\nngx.HTTP_PUT        = 16\r\nngx.HTTP_DELETE     = 32\r\nngx.HTTP_MKCOL      = 64\r\nngx.HTTP_COPY       = 128\r\nngx.HTTP_MOVE       = 256\r\nngx.HTTP_OPTIONS    = 512\r\nngx.HTTP_PROPFIND   = 1024\r\nngx.HTTP_PROPPATCH  = 2048\r\nngx.HTTP_LOCK       = 4096\r\nngx.HTTP_UNLOCK     = 8192\r\nngx.HTTP_PATCH      = 16384\r\nngx.HTTP_TRACE      = 32768<\/pre>\n<h3>2.3 HTTP status constants<\/h3>\n<p><strong>\u4f5c\u7528\u57df:<\/strong>\u00a0<em>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.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*<\/em><\/p>\n<pre>ngx.HTTP_CONTINUE               = 100 \r\nngx.HTTP_SWITCHING_PROTOCOLS    = 101 \r\nngx.HTTP_OK                     = 200\r\nngx.HTTP_CREATED                = 201\r\nngx.HTTP_ACCEPTED               = 202 \r\nngx.HTTP_NO_CONTENT             = 204 \r\nngx.HTTP_PARTIAL_CONTENT        = 206 \r\nngx.HTTP_SPECIAL_RESPONSE       = 300\r\nngx.HTTP_MOVED_PERMANENTLY      = 301\r\nngx.HTTP_MOVED_TEMPORARILY      = 302\r\nngx.HTTP_SEE_OTHER              = 303\r\nngx.HTTP_NOT_MODIFIED           = 304\r\nngx.HTTP_TEMPORARY_REDIRECT     = 307 \r\nngx.HTTP_BAD_REQUEST            = 400\r\nngx.HTTP_UNAUTHORIZED           = 401\r\nngx.HTTP_PAYMENT_REQUIRED       = 402 \r\nngx.HTTP_FORBIDDEN              = 403\r\nngx.HTTP_NOT_FOUND              = 404\r\nngx.HTTP_NOT_ALLOWED            = 405\r\nngx.HTTP_NOT_ACCEPTABLE         = 406 \r\nngx.HTTP_REQUEST_TIMEOUT        = 408 \r\nngx.HTTP_CONFLICT               = 409 \r\nngx.HTTP_GONE                   = 410\r\nngx.HTTP_UPGRADE_REQUIRED       = 426 \r\nngx.HTTP_TOO_MANY_REQUESTS      = 429 \r\nngx.HTTP_CLOSE                  = 444 \r\nngx.HTTP_ILLEGAL                = 451 \r\nngx.HTTP_INTERNAL_SERVER_ERROR  = 500\r\nngx.HTTP_METHOD_NOT_IMPLEMENTED = 501\r\nngx.HTTP_BAD_GATEWAY            = 502 \r\nngx.HTTP_SERVICE_UNAVAILABLE    = 503\r\nngx.HTTP_GATEWAY_TIMEOUT        = 504 \r\nngx.HTTP_VERSION_NOT_SUPPORTED  = 505 \r\nngx.HTTP_INSUFFICIENT_STORAGE   = 507<\/pre>\n<h3>2.4 Nginx log level constants<\/h3>\n<p><strong>\u4f5c\u7528\u57df:<\/strong>\u00a0<em>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.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*<\/em><\/p>\n<pre>ngx.STDERR  = 0\r\nngx.EMERG   = 1\r\nngx.ALERT   = 2\r\nngx.CRIT    = 3\r\nngx.ERR     = 4\r\nngx.WARN    = 5\r\nngx.NOTICE  = 6\r\nngx.INFO    = 7\r\nngx.DEBUG   = 8<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>ngx_lua\u6a21\u5757\u7684\u539f\u7406\uff1a \u6bcf\u4e2aworker\uff08\u5de5\u4f5c\u8fdb\u7a0b\uff09\u521b\u5efa\u4e00\u4e2aLua VM\uff0cworker\u5185\u6240\u6709\u534f\u7a0b\u5171\u4eabVM\uff1b \u5c06Nginx I\/O\u539f\u8bed\u5c01\u88c5\u540e\u6ce8\u5165 Lua VM\uff0c\u5141\u8bb8Lua\u4ee3\u7801\u76f4\u63a5\u8bbf\u95ee\uff1b \u6bcf\u4e2a\u5916\u90e8\u8bf7\u6c42\u90fd\u7531\u4e00\u4e2aLua\u534f\u7a0b\u5904\u7406\uff0c\u534f\u7a0b\u4e4b\u95f4\u6570\u636e\u9694\u79bb\uff1b Lua\u4ee3\u7801\u8c03\u7528I\/O\u64cd\u4f5c\u7b49\u5f02\u6b65\u63a5\u53e3\u65f6\uff0c\u4f1a\u6302\u8d77\u5f53\u524d\u534f\u7a0b\uff08\u5e76\u4fdd\u62a4\u4e0a\u4e0b\u6587\u6570\u636e\uff09\uff0c\u800c\u4e0d\u963b\u585eworker\uff1b I\/O\u7b49\u5f02\u6b65\u64cd\u4f5c\u5b8c\u6210\u65f6\u8fd8\u539f\u76f8\u5173\u534f\u7a0b\u4e0a\u4e0b\u6587\u6570\u636e\uff0c\u5e76\u7ee7\u7eed\u8fd0\u884c \u7cfb\u5217\u6587\u7ae0\uff1a \u6307\u4ee4\uff1aopenResty\u4e2dngx_lua\u6a21\u5757\u63d0\u4f9b\u7684\u6307\u4ee4 \u5e38\u91cf\uff1aopenResty\u4e2dngx_lua\u6a21\u5757\u63d0\u4f9b\u7684\u5e38\u91cf API\uff1aopenResty\u4e2dngx_lua\u6a21\u5757\u63d0\u4f9b\u7684API &nbsp; \u4e8c\u3001\u5e38\u91cf 2.1 Core constants \u4f5c\u7528\u57df:\u00a0init_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.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua* ngx.OK = 0 ngx.ERROR = -1 ngx.AGAIN = -2 ngx.DONE = -4 ngx.DECLINED = -5 ngx.null \u00a02.2 HTTP method constants \u4f5c\u7528\u57df:\u00a0init_by_lua*, set_by_lua*, rewrite_by_lua*, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-15407","post","type-post","status-publish","format-standard","hentry","category-docker"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15407","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=15407"}],"version-history":[{"count":1,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15407\/revisions"}],"predecessor-version":[{"id":15408,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15407\/revisions\/15408"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=15407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=15407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=15407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}