nginxluanginx-locationopenrestyresty-gwt

nginx access_by_lua not respecting lua_package_path


I have a reverse nginx proxy running with the following in the nginx.config:

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

and then multiple location in the server :

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

      proxy_ignore_client_abort on;

      include cors.conf;

      access_by_lua_file nginx_v4.lua;}

Im running this centos 7 with nginx and lua config at /etc/nginx/ and that what I give in my lua package path. When I run nginx , it works fine to import the lua files (find it in lua_package_path) but for some reason when I run the xxx service it fails with the following:

> 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

for some reason it look in /usr/share/nginx for the lua file which actually lies in /etc/nginx : **file "/usr/share/nginx/nginx_v4.lua": cannot open

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

Any idea why ? This does not work until I hardcode the path .


Solution

  • lua_package_path is where lua looks for libraries, not where nginx looks for lua files.

    You could change 'access_by_lua_file' to 'access_by_lua' with 'require "nginx_v4"', or you could change the location of the Lua file, or the path nginx looks for config using the '-p /path/' startup parameter.