I am now programming in Lua with nginx. I write my Lua file and place it in a directory in /usr/local/nginx/lua
. Then in nginx.conf
I write a location, such as
location /lua {
lua_need_request_body on;
content_by_lua_file lua/test.lua;
}
When I access this location through Nginx, the Lua script will be executed.
In a Lua file, one usually can include your own Lua module, and indicate the search path
common_path = '../include/?.lua;'
package.path = common_path .. package.path
In common Lua programming, a relative path is relative to my Lua file.
But with nginx, the relative paths are relative to the directory where I start Nginx.
Like, I am in /usr/local/nginx
and execute sbin/nginx
, then in Lua package.path
will be the /usr/local/include
.
If I am in /usr/local/nginx/sbin
and execute ./nginx
, then in Lua package.path
will be /usr/local/nginx/include
.
I think the directory I start the nginx server should not been limited, but I don't know how to resolve this.