Jonathan Coe
Jonathan Coe

Reputation: 1485

Running Lua under nginx (writing a website with Lua)

As a learning exercise I've dedicated some time to picking up Lua by creating some basic apps. I've gotten it installed and running great on Natty/Ubuntu, however, I'm a bit lost as to how to get it to play nice with nginx.

I've read a bit here http://wiki.nginx.org/HttpLuaModule#Installation And cloned this repo https://github.com/chaoslawful/lua-nginx-module into my /etc/nginx folder...

However, I'm still rather lost and unsure how to get it working even on a basic level. Is it possible to just include something into my nginx.conf file to handle /lua requests, or do I need to recompile/reinstall nginx altogether? (i'd rather avoid this).

I've already been using php under nginx via fpm for quite a while, but I'm really not sure where to start getting Lua working in a similar fashion.

Upvotes: 9

Views: 11227

Answers (4)

timurb
timurb

Reputation: 5554

In ubuntu you can use lua module for nginx by simply installing nginx-extras.

Upvotes: 3

paul
paul

Reputation: 13481

You need to download three modules and recompile nginx. Here the commands that you need to execute

./configure --prefix=/usr/local/nginx --add-module=../ngx_devel_kit/ --add-module=../lua-nginx-module/

make

make install

After that you can start using using lua in your nginx.conf file

Upvotes: 0

Dayo
Dayo

Reputation: 12805

The ngx_lua module is for running Lua code directly in the nginx webserver. It is possible to run entire Lua applications in this way but this is not the specific target of that module. Actually, some of the module directives specifically should not be used with long running or complex routines.

You will need to recompile Nginx with this module as you cannot just download an Nginx module and use it like that.

To run Lua applications similar to the way you run PHP, you can configure nginx to pass ".lua" requests to a Lua handler (Similar to PHP).

  1. You can set up a webserver such as the Lua webserver, xavante or thttpd or even Apache and "proxy_pass" to this similarly to how many do with Apache for PHP.

  2. You can set Lua up to run as CGI (similar to PHP with FastCGI although Lua does not have the equivalent of FPM) and call this as needed.

You do not need ngx_lua for either of the two options.

Basically, PHP, Lua and such fall under the broad category of "CGI" scripts and any "how to" on running these can be applied to Lua.

BTW openresty is just regular Nginx with some 3rd party modules bundled in including ngx_lua and the people behind openresty are the same behind ngx_lua.

You can manually add as many of the same bundled modules to Nginx yourself as you wish.

Upvotes: 10

finnw
finnw

Reputation: 48659

I haven't tried with the official nginx distribution, but it was easy enough with OpenResty (http://openresty.org/)

See the "getting started" page for a simple nginx.conf to test it.

Upvotes: 6

Related Questions