Skip to content

Instantly share code, notes, and snippets.

@martijngastkemper
Created June 5, 2015 09:47
Show Gist options
  • Select an option

  • Save martijngastkemper/158fc6a945ad4df88053 to your computer and use it in GitHub Desktop.

Select an option

Save martijngastkemper/158fc6a945ad4df88053 to your computer and use it in GitHub Desktop.
Some LUA testing in Nginx
location /test {
content_by_lua '
if ngx.var.arg_name == nil then
ngx.say("name: missing")
else
ngx.say("name: [", ngx.var.arg_name, "]")
end
';
}
location /website {
internal;
echo "website test";
}
location /sub {
set $sub 'empty';
content_by_lua '
local res = ngx.location.capture("/website")
ngx.say( res.body )
ngx.var.sub = res.body
';
# echo "$sub = ${sub}";
}
location /mysql {
content_by_lua '
local fwm = require "fifthgear.website"
local mysql = require "resty.mysql"
local website = fwm(mysql)
local host = ngx.unescape_uri(ngx.var.host)
local quoted_name = ngx.quote_sql_str(host)
local path, err = website:getInfo(quoted_name)
if err then
ngx.exit(404)
end
ngx.say("result: " , path)
';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment