nginx access_by_lua 没有遵守 lua_package_path

我正在运行反向 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;}

我正在运行的是带有 nginx 和 lua 配置的 centos 7,路径为 **/etc/nginx/**,这就是我在 lua package path 中给的路径。当我运行 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 中查找 lua 文件,而实际上它位于 /etc/nginx 中:**file "/usr/share/nginx/nginx_v4.lua": cannot open

/usr/share/nginx/nginx_v4.lua: No such file or directory**

有什么想法吗?这只有在我硬编码路径之后才能工作。

点赞
用户4554496
用户4554496

lua_package_path 是 Lua 查找库的位置,而非 Nginx 查找 Lua 文件的位置。

您可以通过使用 require "nginx_v4"access_by_lua_file 改为 access_by_lua,或者改变 Lua 文件的位置,或者使用 -p/path/ 启动参数改变 Nginx 查找配置文件的路径。

2016-10-12 08:57:07