前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >nginx lua重置请求参数及常量备忘

nginx lua重置请求参数及常量备忘

作者头像
code4it
发布2018-09-17 15:28:40
1.8K0
发布2018-09-17 15:28:40
举报
文章被收录于专栏:码匠的流水账

本文主要讲述一下nginx lua如何重置请求参数以及整理了几类常量。

重置请求参数

获取请求参数

代码语言:javascript
复制
local strider = ngx.var.arg_strider
local strider = ngx.req.get_uri_args["strider"]

当请求uri中有多个同名参数时,ngx.var.arg_xx的做法是取第一个出现的值,ngx.req_get_uri_args[“xx”]的做法是返回一个table,该table里存放了该参数的所有值

重置参数

代码语言:javascript
复制
local args = ngx.req.get_uri_args()
args["userId"]="override value"
ngx.req.set_uri_args(args)

log级别常量

  • ngx.STDERR — 标准输出
  • ngx.EMERG — 紧急报错
  • ngx.ALERT — 报警
  • ngx.CRIT — 严重,系统故障,触发运维告警系统
  • ngx.ERR — 错误,业务不可恢复性错误
  • ngx.WARN — 告警,业务中可忽略错误
  • ngx.NOTICE — 提醒,业务比较重要信息
  • ngx.INFO — 信息,业务琐碎日志信息,包含不同情况判断等
  • ngx.DEBUG — 调试

使用实例

代码语言:javascript
复制
ngx.log(ngx.ERR,"error occur in ...")

http status code常量

1xx

  • ngx.HTTP_CONTINUE (100) (first added in the v0.9.20 release)
  • ngx.HTTP_SWITCHING_PROTOCOLS (101) (first added in the v0.9.20 release)

2xx

  • ngx.HTTP_OK (200)
  • ngx.HTTP_CREATED (201)
  • ngx.HTTP_ACCEPTED (202) (first added in the v0.9.20 release)
  • ngx.HTTP_NO_CONTENT (204) (first added in the v0.9.20 release)
  • ngx.HTTP_PARTIAL_CONTENT (206) (first added in the v0.9.20 release)

3xx

  • 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) (first added in the v0.9.20 release)

4xx

  • ngx.HTTP_BAD_REQUEST (400)
  • ngx.HTTP_UNAUTHORIZED (401)
  • ngx.HTTP_PAYMENT_REQUIRED (402) (first added in the v0.9.20 release)
  • ngx.HTTP_FORBIDDEN (403)
  • ngx.HTTP_NOT_FOUND (404)
  • ngx.HTTP_NOT_ALLOWED (405)
  • ngx.HTTP_NOT_ACCEPTABLE (406) (first added in the v0.9.20 release)
  • ngx.HTTP_REQUEST_TIMEOUT (408) (first added in the v0.9.20 release)
  • ngx.HTTP_CONFLICT (409) (first added in the v0.9.20 release)
  • ngx.HTTP_GONE (410)
  • ngx.HTTP_UPGRADE_REQUIRED (426) (first added in the v0.9.20 release)
  • ngx.HTTP_TOO_MANY_REQUESTS (429) (first added in the v0.9.20 release)
  • ngx.HTTP_CLOSE (444) (first added in the v0.9.20 release)
  • ngx.HTTP_ILLEGAL (451) (first added in the v0.9.20 release)

5xx

  • ngx.HTTP_INTERNAL_SERVER_ERROR (500)
  • ngx.HTTP_METHOD_NOT_IMPLEMENTED (501)
  • ngx.HTTP_BAD_GATEWAY (502) (first added in the v0.9.20 release)
  • ngx.HTTP_SERVICE_UNAVAILABLE (503)
  • ngx.HTTP_GATEWAY_TIMEOUT (504) (first added in the v0.3.1rc38 release)
  • ngx.HTTP_VERSION_NOT_SUPPORTED (505) (first added in the v0.9.20 release)
  • ngx.HTTP_INSUFFICIENT_STORAGE (507) (first added in the v0.9.20 release)

主要用来设置http 返回状态码

使用实例

代码语言:javascript
复制
if token == nil then
    ngx.exit(ngx.HTTP_FORBIDDEN)
end

doc

  • Lua_Nginx_API
本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2017-11-30,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 码匠的流水账 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 重置请求参数
    • 获取请求参数
      • 重置参数
      • log级别常量
      • http status code常量
        • 1xx
          • 2xx
            • 3xx
              • 4xx
                • 5xx
                • doc
                领券
                问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档