why return HTTP 500 when use the require "resty.memcached" in HttpLuaModule module?

agentzh agentzh at gmail.com
Sat Jun 16 08:22:35 UTC 2012


On Sat, Jun 16, 2012 at 2:44 PM, Xiangong Yang <monitor.xoyo at gmail.com> wrote:
> # set search paths for pure Lua external libraries (';;' is the default
> path):
> lua_package_path
> "/usr/lib/?.lua;/usr/local/lib/?.lua;/usr/local/lib/lua/5.1/?.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/?.lua;/usr/local/lib/lua/resty/?.lua;;";
> # set search paths for Lua external libraries written in C (can also use
> '/bar/baz/?.so;/blah/blah/?.so;;'):

This is really a FAQ for Lua beginners, not specific to ngx_lua. In
short, you should really use "/usr/local/lib/lua/?.lua" in your
lua_package_path here instead of "/usr/local/lib/lua/resty/?.lua"
because you're requiring "resty.memcached" below in your Lua code,
which will make the Lua VM substitute the "?" part in your search path
with the string "resty/memcached" rather than "memcached".

I suggest you just use the ngx_openresty bundle directly. It has all
the components and search paths properly pre-configured for you :) But
there's nothing that can stop you from doing all these configurations
yourself :)

> the require "resty.memcached" code leads the nginx retrun HTTP 500 (500
> Internal Server Error)

When you see 500 or empty reply from the server, you should always
check out your nginx's error.log file for detailed error messages. If
you do, you'll see from error.log that lua fails to find
resty.memcached in your search paths.

BTW, you're recommended to use LuaJIT 2.0 instead of the standard Lua
5.1 interpreter with ngx_lua, see:


Because LuaJIT 2.0 is usually much faster and smaller (in terms of
memory footprint) and has many less limitations in terms of
functionalities as compared to the standard Lua 5.1 interpreter.

Best regards,

More information about the nginx mailing list