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

i use agentzh’s three modules.

CentOS 5.5 x86_64

nginx version is 1.3.1

LUA version:
[root@db2 conf]# *lua -v
*Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
[root@db2 conf]# *luac -v
*Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio

the lua-resty-memcached is installed.

[root@db2 conf]# *ll /usr/local/lib/lua/resty/
*total 12
-rwxr-xr-x 1 root root 11778 Jun 16 16:27 memcached.lua

nginx configuration

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;;’):
lua_package_cpath ‘/usr/lib64/lua/5.1/?.so;/usr/lib64/lua/5.1/?/?.so;;’;

server {

location ~ “^/property/([0-9]+)” {
charset utf-8;
default_type ‘text/plain’;
xss_callback_arg callback;
xss_get on;
#content_by_lua “ngx.say(‘Hello,world!’)”;
content_by_lua ’
local memcached = require “resty.memcached”
';
}

}

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

why the nginx return HTTP 500 when i use the require
“resty.memcached”
?

Are there some lua dependencies that i’ve not installed?

best regards.

Thank you very much! agentzh.

I use the OpenResty successfully now.
How powerfully it is!

and thank you for your sugguestion about LuaJIT.

But i’ve two problem:
1, how to upgrate the nginx to the latest version, eg: nginx 1.3.1 ?
2, how to add the other third module, eg: nginx_concat_module and
substitutions4nginx ?

2012/6/16 agentzh [email protected]

Hello!

On Sat, Jun 16, 2012 at 2:44 PM, Xiangong Y. [email protected]
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 :slight_smile: But
there’s nothing that can stop you from doing all these configurations
yourself :slight_smile:

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:

http://luajit.org/download.html

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,
-agentzh

Thank you very much! agentzh.
You’re always awesome for your friendly and .and your great
contribitons.

now i accepted the two suggustion to upgrate my nginx version and add
the
other 3rd-party modules.
It’s very happy work.

Thank you again.

2012/6/16 agentzh [email protected]

Hello!

On Sat, Jun 16, 2012 at 9:46 PM, Xiangong Y. [email protected]
wrote:

Thank you very much! agentzh.

I use the OpenResty successfully now.
How powerfully it is!

Glad you like it :slight_smile:

and thank you for your sugguestion about LuaJIT.

You’re welcome :slight_smile:

But i’vetwo problem:
1, how to upgrate the nginx to the latest version, eg: nginx 1.3.1 ?

One of the main points of the ngx_openresty bundle is to ensure that
all the bundled components play well with the standard nginx core
bundled. New releases of the Nginx core might break existing 3rd-party
modules. It happens from time to time. Because we’re still testing
compatibility of all the modules with nginx 1.2.x, we’re not ready to
release an ngx_openresty version based on nginx 1.2.x or even 1.3.x.

But you can always replace the bundle/nginx-1.0.15/ directory in
ngx_openresty’s source tree with your own verison of nginx source
tree, like nginx 1.3.1’s, and the ./configure script will just pick it
up. You’re at your own risk though but we’re still very willing to
hear about any problems that you have :slight_smile:

2, how to add the other third module, eg: nginx_concat_module and
substitutions4nginx ?

The ./configure script provided by ngx_openresty supports all the
options of the standard nginx’s ./configure options. Just use the
–add-module=PATH option to add your own 3rd-party modules as usual :slight_smile:

See ./configure --help for a list of all the options that you can use.

Best regards,
-agentzh