Win下载地址:http://code.google.com/p/luaforwindows/
Hello Lua
nginx通过content_by_lua和content_by_lua_file来嵌入lua脚本。
content_by_lua
修改nginx配置文件nginx.conf
location /hellolua {
content_by_lua '
ngx.header.content_type = "text/html";
ngx.say("Hello Lua.");
';
}
重启nginx访问 http://localhost//hellolua 应该可以看到 Hello Lua.
content_by_lua_file
location /demo {
lua_code_cache off;
content_by_lua_file lua_script/demo.lua;
}
lua_code_cache表示关掉缓存,缓存关掉的情况下修改lua脚本不需要重启nginx。content_by_lua_file指定脚本路径。此处为相对路径,相对于nginx根目录,然后写上下面lua脚本
-- filename:demo.lua
ngx.header.content_type = "text/html"
ngx.say("Hello Lua Demo.")
重启Nginx,关掉lua_code_cache后nginx会有个alert。
nginx: [alert] lua_code_cache is off; this will hurt performance in ./conf/nginx.conf:56
访问 http://localhost/demo 则可以看到 Hello Lua Demo.
Nginx常用参数获取
ngx.header.content_type = "text/html"
ngx.header.PowerBy = "Lua"
-- 请求头table
for k, v in pairs(ngx.req.get_headers()) do
ngx.say(k, ": ", v)
end
-- 请求方法 GET、POST等
ngx.say("METHOD:" .. ngx.var.request_method)
-- 获取GET参数
for k, v in pairs(ngx.req.get_uri_args()) do
ngx.say(k, ":", v)
end
-- 获取POST参数
ngx.req.read_body()
for k, v in pairs(ngx.req.get_post_args()) do
ngx.say(k, ":", v)
end
-- HTTP版本
ngx.say(ngx.req.http_version())
-- 未解析的请求头字符串
ngx.say(ngx.req.raw_header())
-- 未解析的BODY字符串
ngx.print(ngx.req.get_body_data())
-- ngx.exit(400)
-- ngx.redirect("/", 200)
获取MD5示例
下面看个小例子,生成字符串的md5值。
ngx.header.content_type = "text/html"
local resty_md5 = require "resty.md5"
local md5 = resty_md5:new()
local s = "Hello Lua."
md5:update(s)
local str = require "resty.string"
ngx.say(str.to_hex(md5:final()))
ngx.say(ngx.md5(s))
凡尔赛法环免广告版 最新版v1.69.1
下载天煞异种 安卓版v1.0.21
下载十三月 (Undecember)最新官方中文版v3.26.0200
下载我不是废柴无限99999钻999999金币游戏 不减反增版v1.2.16
下载我的女友是声优免广告 安卓版v1
我的女友是声优免广告是一款非常好玩的模拟经营类手游,玩家在游
石器帝国去广告版 v8
石器帝国免广告版是游戏的破解版本,在该版本中为玩家去除了广告
校园恋爱模拟器真人版去广告版 v0.0.7
校园恋爱模拟器真人版免广告版是游戏的破解版本,在该版本中为玩
教练我要开球馆内置菜单修改器 安卓版v1.5.4
教练我要开球馆内购版是一款模拟经营类游戏,玩家们将在游戏中创
我的游轮无限砖石 安卓版v1.7.0
我的游轮无限金币钻石版是一款模拟经营类游戏,你将成为一艘游轮