【问题标题】:nginx access_by_lua not respecting lua_package_pathnginx access_by_lua 不尊重 lua_package_path
【发布时间】:2017-02-20 16:15:13
【问题描述】:

我有一个反向 nginx 代理,在 nginx.config 中运行以下内容:

http {
  lua_package_path ";;$prefix/?.lua;?.lua;/etc/nginx/?.lua;/etc/nginx/resty/?.lua;";
}

然后是服务器中的多个位置:

 # xxx SERVICE
    location ~* ^/articles/?(.*) {

      proxy_ignore_client_abort on;

      include cors.conf;

      access_by_lua_file nginx_v4.lua;}

我在 /etc/nginx/ 使用 nginx 和 lua 配置运行这个 centos 7,以及我在 lua 包路径中给出的内容。当我运行 nginx 时,可以正常导入 lua 文件(在 lua_package_path 中找到它),但是由于某种原因,当我运行 xxx 服务时,它会失败并显示以下内容:

> 2016/10/11 16:37:21 [notice] 19300#0: getrlimit(RLIMIT_NOFILE):
> 1024:4096 2016/10/11 16:37:21 [notice] 19301#0: start worker processes
> 2016/10/11 16:37:21 [notice] 19301#0: start worker process 19303
> 2016/10/11 16:37:25 [error] 19303#0: *1 failed to load external Lua
> file "/usr/share/nginx/nginx_v4.lua": cannot open
> /usr/share/nginx/nginx_v4.lua: No such file or directory, client:
> 10.1.104.135, server: localhost, request: "GET /content/search?filter.search_string=goog HTTP/1.1", host: "x.x.x.x"
> 2016/10/11 16:37:41 [info] 19303#0: *2 client closed connection while
> waiting for request, client: 10.1.104.135, server: 0.0.0.0:443

由于某种原因,它在 /usr/share/nginx 中查找实际位于 /etc/nginx 中的 lua 文件:**file "/usr/share/nginx/nginx_v4.lua": cannot open

/usr/share/nginx/nginx_v4.lua:没有这样的文件或目录**

知道为什么吗?在我硬编码路径之前,这不起作用。

【问题讨论】:

    标签: nginx lua nginx-location openresty resty-gwt


    【解决方案1】:

    lua_package_path 是 lua 查找库的位置,而不是 nginx 查找 lua 文件的位置。

    您可以使用 'require "nginx_v4"' 将 'access_by_lua_file' 更改为 'access_by_lua',或者您可以更改 Lua 文件的位置,或者使用 '-p /path/' 启动参数 nginx 查找配置的路径.

    【讨论】:

      猜你喜欢
      • 2016-06-11
      • 1970-01-01
      • 1970-01-01
      • 2017-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-10
      • 2011-04-30
      相关资源
      最近更新 更多