linux - 用Lua分割字符串

标签 linux nginx lua

我的字符串如下所示:nxs_dev_flo.nexus 我只想返回 nxs_dev_flo

这是我尝试过的:

location /luatest {
   default_type 'text/plain';
   content_by_lua 'ngx.say(split(ngx.var.host, "."))';
}

我在日志中收到 500 错误:

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 不是标准的 Lua 函数,显然也不是 nginx 提供的函数。

尝试使用 ngx.say(ngx.var.host:match("(.-)%.")) 代替。

string.match是一个标准的 Lua 函数。

关于linux - 用Lua分割字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48648225/

相关文章:

lua - WoW - 在 Lua 中四舍五入到两位小数

plugins - 为什么使用Lua进行配置/插件?

linux - numactl 中的节点距离是什么意思?

c - 边缘触发的非阻塞 epoll 的 SSL_accept 总是返回 SSL_ERROR_WANT_READ

node.js - 502 Bad Gateway - Ubuntu 16.04.2 LTS 上的 Meteor 和 nginx

c - 为什么Nginx需要内存对齐

nginx - 主机的 Kubernetes Ingress 白名单 IP

lua - 如何解密Lua字节码?

mysql - 升级 Bugzilla 获取错误表已存在

linux - 如果文件在 linux bash 中为空,我如何获得回显输出?