Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting error while using lua with nginx

Tags:

nginx

lua

I am very new to nginx and lua .i have installed Openresty . below is my code in nginx.conf file .

server{
      location /hellolua {
      default_type 'text/plain';
        content_by_lua '        local name = ngx.var.arg_name or "Anonymous"
        ngx.say("Hello, ", name, "!")    ';
        }
       }

When i am running

sudo service nginx start
i am getting error
Starting nginx: nginx: [emerg] unknown directive "content_by_lua" in /etc/nginx/nginx.conf:24
nginx: configuration file /etc/nginx/nginx.conf test failedt
Please let me know what i am missing .
like image 947
Prashant Gaur Avatar asked Nov 08 '13 07:11

Prashant Gaur


People also ask

Does nginx support Lua?

Enable Lua for NginxSome older versions of Nginx don't support native loading of Lua modules. Therefore, we require Nginx to be built with Lua and LuaJIT support.

How does Lua work with nginx?

Nginx+Lua is a self-contained web server embedding the scripting language Lua. Powerful applications can be written directly inside Nginx without using cgi, fastcgi, or uwsgi. By adding a little Lua code to an existing Nginx configuration file, it is easy to add small features.

What version of Lua does OpenResty use?

LuaJIT 2.0. x is always supported in OpenResty though LuaJIT 2.1+ is highly recommended.


2 Answers

By default, OpenResty's nginx is installed into the path /usr/local/openresty/nginx/sbin/nginx. Your system's default nginx init configurations need an update to point to the right locations.

like image 20
agentzh Avatar answered Sep 22 '22 00:09

agentzh


It seems to me, as if you haven't installed the right module? ngx_lua (http://wiki.nginx.org/HttpLuaModule)

You mention OpenResty. Did you configure it with lua? If not, the guide is here(http://wiki.nginx.org/HttpLuaModule#Installation).
Quick resumé:

The ngx_openresty bundle can be used to install Nginx, ngx_lua, either one of the standard Lua 5.1 interpreter or LuaJIT 2.0, as well as a package of powerful companion Nginx modules. The basic installation step is a simple ./configure --with-luajit && make && make install.

You can manually compile ngx_lua into nginx too, the full guide is in the link too.

After comment-discussing - I removed the irrelevant part of the answer.

like image 68
Frederik Spang Avatar answered Sep 19 '22 00:09

Frederik Spang