文档章节

openResty框架整理

孙本新
 孙本新
发布于 2014/10/24 14:14
字数 532
阅读 151
收藏 0

#openResty框架整理# ##相关网址## nginx wiki git仓库位置

##HttpLuaModule##

This module embeds Lua, via the standard Lua 5.1 interpreter or LuaJIT 2.0/2.1, into Nginx and by leveraging Nginx's subrequests, allows the integration of the powerful Lua threads (Lua coroutines) into the Nginx event model.

Unlike Apache's mod_lua and Lighttpd's mod_magnet, Lua code executed using this module can be 100% non-blocking on network traffic as long as the Nginx API for Lua provided by this module is used to handle requests to upstream services such as MySQL, PostgreSQL, Memcached, Redis, or upstream HTTP web services.

Almost all the Nginx modules can be used with this ngx_lua module by means of ngx.location.capture or ngx.location.capture_multi but it is recommended to use those lua-resty-* libraries instead of creating subrequests to access the Nginx upstream modules because the former is usually much more flexible and memory-efficient.

The Lua interpreter or LuaJIT instance is shared across all the requests in a single nginx worker process but request contexts are segregated using lightweight Lua coroutines.

Loaded Lua modules persist in the nginx worker process level resulting in a small memory footprint in Lua even when under heavy loads.

典型应用: Mashup'ing and processing outputs of various nginx upstream outputs (proxy, drizzle, postgres, redis, memcached, and etc) in Lua, doing arbitrarily complex access control and security checks in Lua before requests actually reach the upstream backends, manipulating response headers in an arbitrary way (by Lua) fetching backend information from external storage backends (like redis, memcached, mysql, postgresql) and use that information to choose which upstream backend to access on-the-fly, coding up arbitrarily complex web applications in a content handler using synchronous but still non-blocking access to the database backends and other storage, doing very complex URL dispatch in Lua at rewrite phase, using Lua to implement advanced caching mechanism for Nginx's subrequests and arbitrary locations

HTTP 1.0 support

The HTTP 1.0 protocol does not support chunked output and requires an explicit Content-Length header when the response body is not empty in order to support the HTTP 1.0 keep-alive. So when a HTTP 1.0 request is made and the lua_http10_buffering directive is turned on, ngx_lua will buffer the output of ngx.say and ngx.print calls and also postpone sending response headers until all the response body output is received. At that time ngx_lua can calculate the total length of the body and construct a proper Content-Length header to return to the HTTP 1.0 client. If the Content-Length response header is set in the running Lua code, however, this buffering will be disabled even if the lua_http10_buffering directive is turned on.

For large streaming output responses, it is important to disable the lua_http10_buffering directive to minimise memory usage.

Note that common HTTP benchmark tools such as ab and http_load issue HTTP 1.0 requests by default. To force curl to send HTTP 1.0 requests, use the -0 option.

##Data Sharing within an Nginx Worker ## -- mydata.lua local _M = {}

local data = {
    dog = 3,
    cat = 4,
    pig = 5,
}

function _M.get_age(name)
    return data[name]
end

return _M

此数据在进程间独享。

© 著作权归作者所有

上一篇: Lua 学习整理
下一篇: shell 中括号
孙本新
粉丝 1
博文 17
码字总数 4884
作品 0
海淀
程序员
私信 提问
OpenResty学习资料收集

1、nginx-lua-module使用 https://github.com/iresty/nginx-lua-module-zh-wiki https://github.com/openresty/lua-nginx-module#readme 2、OpenResty最佳实践 https://www.gitbook.com/book......

workming
2018/06/29
0
0
OpenResty x Open Talk 丨北京站

一、活动介绍 OpenResty 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 ...

又拍云
03/04
0
0
openresty调用自己编译C动态库,无法找到其自己动态库依赖的库

使用FFI编写一个动态库,库里面调用openssl及相关的库,但是加载到openresty时,无法找到其依赖的openssl库和第三方的库,并且已放到usr/lib目录性,并在 lua_package_cpath '/lib64/?.so;/...

vanlee90
2016/09/26
628
1
OSC 第 105 期高手问答 —— 高性能 Web 应用开发

OSCHINA 本期高手问答( 12月23日- 12月29日)我们请来了 Vanilla 的开发者@iDev_周晶 来解答 从 Vanilla 开始做 OpenResty 高性能 Web 应用开发 方面的问题。 周晶,@iDev_周晶 ,新浪移动事业...

叶秀兰
2015/12/22
13.8K
41
好未来吴钧泽:当 OpenResty 遇上教育行业

2019 年 3 月 23 日,OpenResty 社区联合又拍云,举办 OpenResty × Open Talk 全国巡回沙龙·北京站,好未来高级工程师吴钧泽在活动上做了《 当 OpenResty 遇上教育行业 》的分享。 OpenRe...

又拍云
04/11
0
0

没有更多内容

加载失败,请刷新页面

加载更多

以太坊私有链搭建

https://blog.csdn.net/Blockchain_lemon/article/details/80589123

Moks角木
31分钟前
1
0
自律给我自信-为什么要自律

为什么要自律 混一天和努力一天 看不到任何差别 3天看不到任何变化 7天也看不到任何效果 但是 1个月后, 会看到话题不同 3个月后, 会看到气场不同 6个月后, 会看到距离不同 3年后, 会看到...

周大壮
31分钟前
1
0
读书replay计划说明

突然脑袋一闪,我有了这样一个主意:通过写博客的方式,将我阅读的书中的内容replay出来。 我一般会找着我感兴趣的书去读,一般也会读书中我感兴趣的章节,或者当下对我有用的章节,所以这个...

wanxiangming
33分钟前
0
0
CentOS7安装xrdp环境可实现远程桌面访问

CentOS7安装xrdp环境可实现远程桌面访问 2018-07-14 06:39:28 分类:运维 阅读(2051) 评论(0) 在"Ubuntu系统安装xrdp桌面客户端及实现远程连接桌面"文章中有分享过在Ubuntu系统中安装XRDP环境...

linjin200
58分钟前
4
0
ConfigurationProperties

package cn.enjoy.config; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; @ConfigurationProperties(pr......

少年已不再年少
今天
2
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部