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

**URL:** <https://www.ruby-forum.com/t/why-return-http-500-when-use-the-require-resty-memcached-in-httpluamodule-module/220674>\
**Category:** NGINX\
**Created:** [June 16, 2012, 8:45am UTC](https://www.ruby-forum.com/t/why-return-http-500-when-use-the-require-resty-memcached-in-httpluamodule-module/220674 "2012-06-16T08:45:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [June 16, 2012, 8:45am UTC](https://www.ruby-forum.com/t/why-return-http-500-when-use-the-require-resty-memcached-in-httpluamodule-module/220674/1 "2012-06-16T08:45:00Z")

</div>

i use agentzh’s three modules.

> **[Lua | NGINX](https://www.nginx.com/resources/wiki/modules/lua/)**
>
> The Lua module embeds Lua into NGINX and by leveraging NGINX's subrequests, allows the integration of Lua threads into the NGINX event model.

> **[GitHub - openresty/xss-nginx-module: Native support for cross-site scripting...](https://github.com/openresty/xss-nginx-module)**
>
> Native support for cross-site scripting (XSS) in an nginx - GitHub - openresty/xss-nginx-module: Native support for cross-site scripting (XSS) in an nginx

> **[GitHub - openresty/lua-resty-memcached: Lua memcached client driver for the...](https://github.com/openresty/lua-resty-memcached)**
>
> Lua memcached client driver for the ngx\_lua based on the cosocket API - GitHub - openresty/lua-resty-memcached: Lua memcached client driver for the ngx\_lua based on the cosocket API

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](http://Lua.org), PUC-Rio  
[root@db2 conf]# \*luac -v  
\*Lua 5.1.5 Copyright (C) 1994-2012 [Lua.org](http://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.

---

<div class="post-metadata">

**Author:** ![Xiangong\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/94ad74/32.png) [@Xiangong\_Y](https://www.ruby-forum.com/u/Xiangong_Y)\
**Post date:** [June 16, 2012, 3:46pm UTC](https://www.ruby-forum.com/t/why-return-http-500-when-use-the-require-resty-memcached-in-httpluamodule-module/220674/2 "2012-06-16T15:46:49Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Xiangong\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/94ad74/32.png) [@Xiangong\_Y](https://www.ruby-forum.com/u/Xiangong_Y)\
**Post date:** [June 16, 2012, 10:23am UTC](https://www.ruby-forum.com/t/why-return-http-500-when-use-the-require-resty-memcached-in-httpluamodule-module/220674/3 "2012-06-16T10:23:09Z")

</div>

Hello!

On Sat, Jun 16, 2012 at 2:44 PM, Xiangong Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
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:

```
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

---

<div class="post-metadata">

**Author:** ![Xiangong\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/94ad74/32.png) [@Xiangong\_Y](https://www.ruby-forum.com/u/Xiangong_Y)\
**Post date:** [June 17, 2012, 4:40am UTC](https://www.ruby-forum.com/t/why-return-http-500-when-use-the-require-resty-memcached-in-httpluamodule-module/220674/4 "2012-06-17T04:40:56Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Xiangong\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/94ad74/32.png) [@Xiangong\_Y](https://www.ruby-forum.com/u/Xiangong_Y)\
**Post date:** [June 16, 2012, 5:33pm UTC](https://www.ruby-forum.com/t/why-return-http-500-when-use-the-require-resty-memcached-in-httpluamodule-module/220674/5 "2012-06-16T17:33:45Z")

</div>

Hello!

On Sat, Jun 16, 2012 at 9:46 PM, Xiangong Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Thank you very much! agentzh.
> 
> I use the OpenResty successfully now.  
> How powerfully it is!

Glad you like it 🙂

> and thank you for your sugguestion about LuaJIT.

You’re welcome 🙂

> 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 🙂

> 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 🙂

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

Best regards,  
-agentzh
