Running Lua under nginx (writing a website with Lua) Running Lua under nginx (writing a website with Lua) nginx nginx

Running Lua under nginx (writing a website with Lua)


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, xavanteor thttpd or even Apache and "proxy_pass" to this similarly tohow many do with Apache for PHP.

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

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.


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.


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