Created
June 5, 2015 09:47
-
-
Save martijngastkemper/158fc6a945ad4df88053 to your computer and use it in GitHub Desktop.
Some LUA testing in Nginx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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