当前位置: 首页 > news >正文

建设网站必备的开发工具南宁做网站公司

建设网站必备的开发工具,南宁做网站公司,红河州网站建设制作,进一步加强政府网站内容建设openresty ngx_lua常用指令 请求中断 ngx.exit:请求中断 语法格式:ngx.exit(status) * status > 200:立刻中断请求,返回状态码 * status 0:中断当前执行阶段,继续执行后续阶段环境:rewrite…

openresty ngx_lua常用指令

            

                    

                                   

请求中断

        

ngx.exit:请求中断

语法格式:ngx.exit(status)
* status >= 200:立刻中断请求,返回状态码
* status == 0:中断当前执行阶段,继续执行后续阶段环境:rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, ngx.timer.*, balancer_by_lua*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_session_store_by_lua*, ssl_client_hello_by_lua*

            

请求状态码:status可以用数字、也可以是字面量(ngx.HTTP_OK

   value = ngx.HTTP_CONTINUE (100) (first added in the v0.9.20 release)value = ngx.HTTP_SWITCHING_PROTOCOLS (101) (first added in the v0.9.20 release)value = ngx.HTTP_OK (200)value = ngx.HTTP_CREATED (201)value = ngx.HTTP_ACCEPTED (202) (first added in the v0.9.20 release)value = ngx.HTTP_NO_CONTENT (204) (first added in the v0.9.20 release)value = ngx.HTTP_PARTIAL_CONTENT (206) (first added in the v0.9.20 release)value = ngx.HTTP_SPECIAL_RESPONSE (300)value = ngx.HTTP_MOVED_PERMANENTLY (301)value = ngx.HTTP_MOVED_TEMPORARILY (302)value = ngx.HTTP_SEE_OTHER (303)value = ngx.HTTP_NOT_MODIFIED (304)value = ngx.HTTP_TEMPORARY_REDIRECT (307) (first added in the v0.9.20 release)value = ngx.HTTP_PERMANENT_REDIRECT (308)value = ngx.HTTP_BAD_REQUEST (400)value = ngx.HTTP_UNAUTHORIZED (401)value = ngx.HTTP_PAYMENT_REQUIRED (402) (first added in the v0.9.20 release)value = ngx.HTTP_FORBIDDEN (403)value = ngx.HTTP_NOT_FOUND (404)value = ngx.HTTP_NOT_ALLOWED (405)value = ngx.HTTP_NOT_ACCEPTABLE (406) (first added in the v0.9.20 release)value = ngx.HTTP_REQUEST_TIMEOUT (408) (first added in the v0.9.20 release)value = ngx.HTTP_CONFLICT (409) (first added in the v0.9.20 release)value = ngx.HTTP_GONE (410)value = ngx.HTTP_UPGRADE_REQUIRED (426) (first added in the v0.9.20 release)value = ngx.HTTP_TOO_MANY_REQUESTS (429) (first added in the v0.9.20 release)value = ngx.HTTP_CLOSE (444) (first added in the v0.9.20 release)value = ngx.HTTP_ILLEGAL (451) (first added in the v0.9.20 release)value = ngx.HTTP_INTERNAL_SERVER_ERROR (500)value = ngx.HTTP_NOT_IMPLEMENTED (501)value = ngx.HTTP_METHOD_NOT_IMPLEMENTED (501) (kept for compatibility)value = ngx.HTTP_BAD_GATEWAY (502) (first added in the v0.9.20 release)value = ngx.HTTP_SERVICE_UNAVAILABLE (503)value = ngx.HTTP_GATEWAY_TIMEOUT (504) (first added in the v0.3.1rc38 release)value = ngx.HTTP_VERSION_NOT_SUPPORTED (505) (first added in the v0.9.20 release)value = ngx.HTTP_INSUFFICIENT_STORAGE (507) (first added in the v0.9.20 release)

           

core constants

ngx.exit accepts ngx.OK, ngx.ERROR, and ngx.DECLINED as input
* ngx.exit只接受ngx.OK, ngx.ERROR, ngx.DECLINED作为输入参数ngx.OK (0)ngx.ERROR (-1)ngx.AGAIN (-2)ngx.DONE (-4)ngx.DECLINED (-5)

          

示例

# 输出自定义内容ngx.status = ngx.HTTP_GONEngx.say("This is our own content")-- to cause quit the whole request rather than the current phase handlerngx.exit(ngx.HTTP_OK)$ curl -i http://localhost/testHTTP/1.1 410 GoneServer: nginx/1.0.6Date: Thu, 15 Sep 2011 00:51:48 GMTContent-Type: text/plainTransfer-Encoding: chunkedConnection: keep-aliveThis is our own content

         

              

                                   

断开连接

        

ngx.eof:告知客户端断开连接

语法格式:ok, err = ngx.eof()
* 告知客户端断开连接,服务端继续执行后续操作
* 如果后续有子请求,子请求会中断
* 设置指令:proxy_ignore_client_abort on;  ==> 子请求继续执行环境:rewrite_by_lua*, access_by_lua*, content_by_lua*

                         

示例

location = /async {keepalive_timeout 0;content_by_lua_block {ngx.say("got the task!")ngx.eof();     --向客户端发出连接中断请求ngx.sleep(3);  --服务端继续执行后续操作ngx.log(ngx.INFO, "执行ngx.eof");}}

        

            

                                   

请求休眠

        

ngx.sleep:请求休眠

语法格式:ngx.sleep(seconds)
* second可以是0.001s环境:rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*, ssl_client_hello_by_lua*

            

示例

location /test {content_by_lua_block {ngx.sleep(5);ngx.say("gtlx");}
}

          

                

                                   

获取时间

        

日期时间

ngx.today()      ==>  yyyy-MM-dd格式的时间
ngx.time()       ==>  当前时间的unix时间戳
ngx.now()        ==>  当前时间的unix时间戳,精确到毫秒(小数点3位)
ngx.localtime()  ==>  yyyy-MM-dd HH:mm:ss(所在时区的时间)
ngx.utctime()    ==>  yyyy-MM-dd HH:mm:ss(0时区)ngx.cookie_time(unix)   ==> cookie过期时间,返回格式:Thu, 18 Nov 2010 11:27:35 GMT
ngx.http_time(unix)     ==> 返回一个可以做header头部(Expires、Last-Modified)时间的格式,如:Thu, 18 Nov 2010 11:27:35 GMT# 输入ngx.http_time(unix)格式的时间,输出unix
ngx.parse_http_time("Thu, 18 Nov 2010 11:27:35 GMT")ngx.update_time():强制更新nginx时间,会影响nginx性能,不推荐使用

              

                         

                                   

编解码

        

编解码

# uri编解码
ngx.escape_uri(uri)     ==>  uri编码成字符串
ngx.unescape_uri(str)   ==>  字符串还原为uri# 参数编解码
ngx.encode_args(table)             ==>  将table类型的数据编码为字符串(uri路径参数)
ngx.decode_args(str, max_args?)    ==>  将uri路径参数解码为table类型数据# md5加密
ngx.md5(str)       ==> 对str进行md5加密,返回16进制字符串
ngx.md5_bin(str)   ==> 对str进行md5加密,返回2进制字符串

         

             

                                   

防止sql注入

        

ngx.quote_sql_str:按照mysql的sql格式,将字符串转换为sql语句

语法格式:quoted_value = ngx.quote_sql_str(raw_value)环境: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*, ssl_client_hello_by_lua*Returns a quoted SQL string literal according to the MySQL quoting rules
* 根据mysql sql语法格式,返回sql语句

         

             

                                   

判断子请求

        

ngx.is_subrequest:判断是否是子请求

语法格式:alue = ngx.is_subrequest
* 当前请求是子请求,返回true
* 当前请求是http请求,返回false环境:set_by_lua*, rewrite_by_lua*, access_by_lua*, content_by_lua*, header_filter_by_lua*, body_filter_by_lua*, log_by_lua*

          

               

http://www.lbrq.cn/news/2499607.html

相关文章:

  • 网站做镜像百度游戏中心
  • 微信制作宣传网站有哪些内容今日十大新闻
  • 广西网站建设哪家好做百度推广怎么做才能有电话
  • 自己如何做独立网站二手交易平台
  • 南昌做网站开发的公司哪家好微营销
  • 工商银行建设银行招商银行网站seo外包收费
  • 企业快速建站必备的几大常识长沙靠谱关键词优化公司电话
  • 可以上传数据的网站开发推广链接点击器网页
  • 汽车之家网站如何免费发布广告
  • 兰州彩票网站制作交换友情链接的网站标准是什么
  • 中山 网站建设一条龙全包app引流推广方法
  • 请人做网站后台密码制作网站的最大公司
  • 莱芜高新区管委会网站长沙免费建站网络营销
  • 做视频网站多大服务器百度一下首页设为主页
  • 潘嘉严个人网站网络营销到底是干嘛的
  • ui做网站实例百度指数只能查90天吗
  • 建设网站的安全性介绍aso优化榜单
  • 如何在jsp上做网站页面代码百度广告收费表
  • 铜川网站建设公司电话舆情信息在哪里找
  • 云电子网站开发近10天的时事新闻
  • vue做单页面网站3322免费域名注册
  • 宿州做企业网站公司美区下载的app怎么更新
  • 东营做网站公司网络营销的概念及内容
  • 国外平面设计师常看的网站名优网站关键词优化
  • 企业铭做网站免费网站站长查询
  • 新网站怎么做才会被收录软文广告素材
  • 百中搜网站建设媒体资源网
  • 珠海做网站方案杭州百度推广优化排名
  • 网站个免费的空间国外搜索引擎大全百鸣
  • 成都网站建设 3e如何推广好一个产品
  • GoLand 项目从 0 到 1:第三天 —— 图数据库版本管理方案调研与中间件部署
  • 架构实战——互联网架构模板(“存储层”技术)
  • KubeSphere理论及实战
  • 嵌入式基础知识复习(7.28)
  • 剑指offer第2版:双指针+排序+分治+滑动窗口
  • 2024-2025华为ICT大赛中国区 实践赛网络赛道(高教组)全国总决赛 理论部分真题+解析