6

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 .

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Double quotes and single quotes are semantically equivalent in Lua: if you start a string with " you must end it with " and use ' inside it with no additional escaping, or you can do vice versa.
Which is exactly what I've done ;-) I'm just following the documentation, to avoid things like nginx not wanting single-quotes. Haven't worked much with nginx.
This is the issue i am not able to configure openresty with lua. i am not able to find path where lua is installed.please help me how can i configure i am so confused
The problem is most likely, Lua simply isn't installed.
@FrederikSpang lua is installed but i am not able to configure with nginx
|
4

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.