Installing Nginx with Lua Module

Download the script.

Or run the following command:

bash < <(curl -s

Note: This script has been tested on Ubuntu 12.04.2 LTS but should work on just about any unix based distro, as everything is compiled from source.

Requires wget and basic build essentials.

What's it do?

  • Download LuaJIT 2.0.1
  • Install LuaJIT 2.0.1
  • Download Nginx Development Kit (NDK)
  • Download lua-nginx-module
  • Download Nginx 1.2.8
  • configure Nginx with lua-nginx-module
  • Install Nginx

Binary Results:

  • /opt/nginx/sbin/nginx
  • /usr/local/bin/lua
  • /usr/local/bin/luajit

Lib Results:

  • /usr/local/lib/*lua*

Include Results:

  • /usr/local/include/luajit-2.0/*

Starting Nginx

LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH /opt/nginx/sbin/nginx -c /path/to/nginx.conf

Update existing Nginx init:

Stop Nginx: sudo /etc/init.d/nginx stop

Patch /etc/init.d/nginx like so:

< PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
< DAEMON=/usr/sbin/nginx
> export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
> # ensure default configuration location
> test "$DAEMON_OPTS" || DAEMON_OPTS="-c /etc/nginx/nginx.conf"
> PATH=/opt/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
> DAEMON=/opt/nginx/sbin/nginx`

Note: the above may not be the best way, but it's what I had to do to get it to work and I didn't have a ton of time to mess with it.