openResty中ngx_lua模块提供的常量

ngx_lua模块的原理:

  1. 每个worker(工作进程)创建一个Lua VM,worker内所有协程共享VM;
  2. 将Nginx I/O原语封装后注入 Lua VM,允许Lua代码直接访问;
  3. 每个外部请求都由一个Lua协程处理,协程之间数据隔离;
  4. Lua代码调用I/O操作等异步接口时,会挂起当前协程(并保护上下文数据),而不阻塞worker;
  5. I/O等异步操作完成时还原相关协程上下文数据,并继续运行

系列文章:
指令:openResty中ngx_lua模块提供的指令
常量:openResty中ngx_lua模块提供的常量
API:openResty中ngx_lua模块提供的API

二、常量

2.1 Core constants

作用域: 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*

ngx.OK          = 0
ngx.ERROR       = -1
ngx.AGAIN       = -2
ngx.DONE        = -4
ngx.DECLINED    = -5
ngx.null

 2.2 HTTP method constants

作用域: 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*

ngx.HTTP_GET        = 2
ngx.HTTP_HEAD       = 4
ngx.HTTP_POST       = 8
ngx.HTTP_PUT        = 16
ngx.HTTP_DELETE     = 32
ngx.HTTP_MKCOL      = 64
ngx.HTTP_COPY       = 128
ngx.HTTP_MOVE       = 256
ngx.HTTP_OPTIONS    = 512
ngx.HTTP_PROPFIND   = 1024
ngx.HTTP_PROPPATCH  = 2048
ngx.HTTP_LOCK       = 4096
ngx.HTTP_UNLOCK     = 8192
ngx.HTTP_PATCH      = 16384
ngx.HTTP_TRACE      = 32768

2.3 HTTP status constants

作用域: 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*

ngx.HTTP_CONTINUE               = 100 
ngx.HTTP_SWITCHING_PROTOCOLS    = 101 
ngx.HTTP_OK                     = 200
ngx.HTTP_CREATED                = 201
ngx.HTTP_ACCEPTED               = 202 
ngx.HTTP_NO_CONTENT             = 204 
ngx.HTTP_PARTIAL_CONTENT        = 206 
ngx.HTTP_SPECIAL_RESPONSE       = 300
ngx.HTTP_MOVED_PERMANENTLY      = 301
ngx.HTTP_MOVED_TEMPORARILY      = 302
ngx.HTTP_SEE_OTHER              = 303
ngx.HTTP_NOT_MODIFIED           = 304
ngx.HTTP_TEMPORARY_REDIRECT     = 307 
ngx.HTTP_BAD_REQUEST            = 400
ngx.HTTP_UNAUTHORIZED           = 401
ngx.HTTP_PAYMENT_REQUIRED       = 402 
ngx.HTTP_FORBIDDEN              = 403
ngx.HTTP_NOT_FOUND              = 404
ngx.HTTP_NOT_ALLOWED            = 405
ngx.HTTP_NOT_ACCEPTABLE         = 406 
ngx.HTTP_REQUEST_TIMEOUT        = 408 
ngx.HTTP_CONFLICT               = 409 
ngx.HTTP_GONE                   = 410
ngx.HTTP_UPGRADE_REQUIRED       = 426 
ngx.HTTP_TOO_MANY_REQUESTS      = 429 
ngx.HTTP_CLOSE                  = 444 
ngx.HTTP_ILLEGAL                = 451 
ngx.HTTP_INTERNAL_SERVER_ERROR  = 500
ngx.HTTP_METHOD_NOT_IMPLEMENTED = 501
ngx.HTTP_BAD_GATEWAY            = 502 
ngx.HTTP_SERVICE_UNAVAILABLE    = 503
ngx.HTTP_GATEWAY_TIMEOUT        = 504 
ngx.HTTP_VERSION_NOT_SUPPORTED  = 505 
ngx.HTTP_INSUFFICIENT_STORAGE   = 507

2.4 Nginx log level constants

作用域: 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*

ngx.STDERR  = 0
ngx.EMERG   = 1
ngx.ALERT   = 2
ngx.CRIT    = 3
ngx.ERR     = 4
ngx.WARN    = 5
ngx.NOTICE  = 6
ngx.INFO    = 7
ngx.DEBUG   = 8

openResty中ngx_lua模块提供的常量》上有2条评论

  1. Pingback引用通告: openresty中ngx_lua模块提供的指令 | 精彩每一天

  2. Pingback引用通告: openResty中ngx_lua模块提供的API | 精彩每一天

发表评论

电子邮件地址不会被公开。 必填项已用*标注

您可以使用这些HTML标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>