nginx lua模块淘宝开发的nginx第三方模块,它能将lua语言嵌入到nginx配置中,从而使用lua就极大增强了nginx的能力.nginx以高并发而知名,lua脚本轻便,两者的搭配堪称完美.接下来请看如何安装nginx + ngx_lua模块.以及最后来个简单的测试.
如果你是ubuntu系统,请看nginx+lua+redis构建高并发应用
系统环境:centos/redhat
安装前准备好如下软件包
· nginx 地址:http://www.nginx.org
· luajit 地址:http://luajit.org/download.html
· HttpLuaModule 地址:http://wiki.nginx.org/HttpLuaModule
1. 下载安装LuaJIT
OK Successfully built LuaJIT |
make [1]: Leaving directory `/usr/ local /src/LuaJIT-2.0.2/src'
|
==== Successfully built LuaJIT 2.0.2 ==== |
==== Successfully installed LuaJIT 2.0.2 to /usr/ local ====
|
2. 下载准备nginx lua模块
3. 安装nginx
3.1 安装
//先导入环境变量,告诉nginx去哪里找luajit |
3.1 常见错误
./objs/nginx: error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file : No such file or directory
|
4. nginx lua配置
nginx配置文件加入如下配置:
location ~* ^/2328(/.*) { |
default_type 'text/plain' ;
|
content_by_lua 'ngx.say("hello, ttlsa lua")' ;
|
5. 启动测试
5.1 启动nginx
5.2 访问测试
hello, ttlsa lua //使用curl测试 |
nginx lua测试截图
nginx lua测试
nginx ngx_lua的安装到此结束
转载请注明出处: http://www.ttlsa.com/html/2328.html
nginx+lua+redis构建高并发应用
ngx_lua将lua嵌入到nginx,让nginx执行lua脚本,高并发,非阻塞的处理各种请求。
url请求nginx服务器,然后lua查询redis,返回json数据。
备注:centos或者redhat系统请跳转到nginx + ngx_lua安装测试
一.安装lua
# apt- get install liblua5. 1 -dev
|
# apt- get install liblua5. 1 -socket2
|
二.安装nginx
# apt- get install git-core
|
# apt- get install libpcre3 libpcre3-dev libltdl-dev libssl-dev libjpeg62 libjpeg62-dev libpng12- 0 libpng12-dev libxml2-dev libcurl4-openssl-dev libmcrypt-dev autoconf libxslt1-dev libgd2-noxpm-dev libgeoip-dev libperl-dev -y
|
# tar zxvf nginx- 1.0 . 8 .tar.gz
|
# ./configure --prefix=/usr/local/nginx -- with -debug -- with -http_addition_module \
|
-- with -http_dav_module -- with -http_flv_module -- with -http_geoip_module \
|
-- with -http_gzip_static_module -- with -http_image_filter_module -- with -http_perl_module \
|
-- with -http_random_index_module -- with -http_realip_module -- with -http_secure_link_module \
|
-- with -http_stub_status_module -- with -http_ssl_module -- with -http_sub_module \
|
-- with -http_xslt_module -- with -ipv6 -- with -sha1=/usr/ include /openssl \
|
-- with -md5=/usr/ include /openssl -- with -mail -- with -mail_ssl_module \
|
--add-module=../ngx_devel_kit \ |
--add-module=../echo-nginx-module \ |
--add-module=../lua-nginx-module \ |
--add-module=../redis2-nginx-module \ |
--add-module=../ngx_http_upstream_keepalive \ |
--add-module=../ set -misc-nginx-module
|
三.安装lua-redis-parser
# export LUA_INCLUDE_DIR=/usr/ include /lua5. 1
|
四.安装json
# unzip json4lua- 0.9 . 50 .zip
|
# cp json4lua- 0.9 . 50 /json/json.lua /usr/share/lua/ 5.1 /
|
五.安装redis-lua
# cp redis-lua/src/redis.lua /usr/share/lua/ 5.1 /
|
六.配置
worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000 ;
|
error_log logs/error.log notice; |
worker_rlimit_nofile 60000 ;
|
default_type application/octet-stream; |
access_log logs/access.log; |
types_hash_max_size 2048 ;
|
server 192.168 . 1.39 : 6379 ;
|
server_name 192.168 . 1.211 ;
|
set_unescape_uri $key $arg_key; |
redis2_query hgetall $key; |
content_by_lua_file conf/fuck.lua; |
# vim fuck.lua
local json = require( "json" )
|
local parser = require( "redis.parser" )
|
local res = ngx.location.capture( "/get_redis" ,{
|
args = { key = ngx. var .arg_key }
|
if res.status == 200 then
|
reply = parser.parse_reply(res.body) |
value = json.encode(reply) |
七.测试
# redis-cli -h 192.168.1.39
redis 192.168 . 1.39 : 6379 > HMSET ttlsa www www.ttlsa.com mail mail.ttlsa.com
|
# curl ‘http://192.168.1.211/json?key=ttlsa’
[ "www" , "www.ttlsa.com" , "mail" , "mail.ttlsa.com" ]
|
www.ttlsa.com
如需转载请注明出处: nginx+lua+redis构建高并发应用
分享到:
相关推荐
Centos 7 64 +[nginx+ngx_lua 模块] 支持WAF防护功能 可以作为喔
ngx_lua 是一个 NGINX 的第三方扩展模块,它能够将 Lua 代码嵌入到 NGINX 中来执行。UPYUN 的 CDN 大量使用了 NGINX 作为反向代理服务器,并开发了一系列例如流量统计、缓存调度、防盗链等相关的 C 模块,但从 2013 ...
lua-upstream-nginx-module, Nginx C 模块将Lua向ngx_lua公开,用于 Nginx upstreams 电子邮件名称ngx_http_lua_upstream - Nginx MODULE,用于向 Nginx upstreams公开Lua到 ngx_lua目录NAME状态概要说明函数get_...
ngx_lua 作者所写,揭示ngx_lua核心技术和开发案列。
nginx lua module for windows 详细请访问 http://blog.csdn.net/ngwsx/
Using ngx_lua in UPYUN 2.pdf
ngx_openresty-1.7.7.2/bundle目录里存放着nginx核心和很多第三方模块,比如有我们需要的Lua和LuaJIT。 3.安装LuaJIT cd bundle/LuaJIT-2.1-20150120/ make clean && make && make install ln -sf luajit-2.
WEB应用防火墙,利用nginx的组件nginx_lua的组件,利用Lua语言开发的一个防火墙,简单
lua-resty-consul, 库与ngx_lua中的consul接口的接口 lua-resty-consul库与ngx_lua中的consul接口的接口目录概述依赖项方法新插件 。get_decodedget_json_decoded把了删除get_client_body_reader
lua_use_default_type lua_code_cache lua_regex_cache_max_entries header_filter_by_lua ngx.headers_sent
ngx_lua_php_queue, nginx lua php redis实现单业务排队系统架构
描述这个Lua库是ngx_lua nginx模块的Redis客户端驱动程序: 这个Lua库利用了ngx_lua的cosocket API,可确保100%的非阻塞行为。 请注意,至少需要或 。概要 # you do not need the following line if you are using ...
lua-resty-http:用于OpenResty ngx_lua的Lua HTTP客户端cosocket驱动程序
而目前市面上用的非常成熟的扩展是由章亦春将Lua和Nginx粘合的ngx_lua模块,并且将Nginx核心、LuaJIT、ngx_lua模块、许多有用的Lua库和常用的第三方Nginx模块组合在一起成为OpenResty,这样开发人员就可以安装...
NULL 博文链接:https://cywhoyi.iteye.com/blog/2118913
ngx_lua_anticc是 Nginx 的 CC(ChallengeCollapsar) 攻击缓解工具。 CC 攻击(即 HTTP 请求泛洪)是一种第 7 层 DDoS 攻击。 ngx_lua_anticc 是 Nginx 基于的扩展。 有了它,您可以轻松地为您的 Web 服务器添加 CC ...
ngx_lua_rate 功能 针对不同的url, 采用不同的过滤控制频率 针对不同的url参数, 采用不同的过滤控制频率 采用两级灰度机制, 针对不同的频率做出不同的React 有白名单/黑名单机制 白名单和黑名单可以写成ip段 注: 需...
nginx集成lua脚本模块,配合nginx和ngx_devel_kit一起使用,注意lua_nginx_module的版本号,否则会出现时间类型不兼容
ngx_lua_metricslua script to emit metrics info to tsdb server从nginx中发送nginx metrics信息到tsdb。主要依赖:1、ngx_lua: 2、cmsgpack: 3、luasocket: 使用方法:1、安装依赖2、nginx配置:lua_package_path ...