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