My string looks like this: nxs_dev_flo.nexus
and I want to return only nxs_dev_flo
Here is what I tried:
location /luatest {
default_type 'text/plain';
content_by_lua 'ngx.say(split(ngx.var.host, "."))';
}
I get a 500 error with this in log:
2018/02/06 17:59:52 [error] 7237#7237: *87 lua entry thread aborted: runtime error: content_by_lua(default:55):1: attempt to call global 'split' (a nil value) stack traceback: coroutine 0: content_by_lua(default:55): in function , client: 127.0.0.1, server: _, request: "GET /luatest HTTP/1.1", host: "nxs_flo_dev.nexus"
split
is not a standard Lua function and apparently not one provided by nginx.
Try ngx.say(ngx.var.host:match("(.-)%."))
instead.
string.match is a standard Lua function.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.