<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://tech.uvoo.io/index.php?action=history&amp;feed=atom&amp;title=NGINX_%2B_LUA_Compile</id>
	<title>NGINX + LUA Compile - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://tech.uvoo.io/index.php?action=history&amp;feed=atom&amp;title=NGINX_%2B_LUA_Compile"/>
	<link rel="alternate" type="text/html" href="https://tech.uvoo.io/index.php?title=NGINX_%2B_LUA_Compile&amp;action=history"/>
	<updated>2026-04-04T22:29:16Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.2</generator>
	<entry>
		<id>https://tech.uvoo.io/index.php?title=NGINX_%2B_LUA_Compile&amp;diff=1137&amp;oldid=prev</id>
		<title>Busk: Created page with &quot;Shameless rip from here. Will clean this up later. - https://tarunlalwani.com/post/building-nginx-with-lua/  Building Nginx from source with LuaJIT Nginx is a great webserver....&quot;</title>
		<link rel="alternate" type="text/html" href="https://tech.uvoo.io/index.php?title=NGINX_%2B_LUA_Compile&amp;diff=1137&amp;oldid=prev"/>
		<updated>2021-01-23T19:37:11Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Shameless rip from here. Will clean this up later. - https://tarunlalwani.com/post/building-nginx-with-lua/  Building Nginx from source with LuaJIT Nginx is a great webserver....&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Shameless rip from here. Will clean this up later.&lt;br /&gt;
- https://tarunlalwani.com/post/building-nginx-with-lua/&lt;br /&gt;
&lt;br /&gt;
Building Nginx from source with LuaJIT&lt;br /&gt;
Nginx is a great webserver. But it has no scripting capabilities. To add scripting capabilities in Nginx, one needs to build it from source with the necessary add-ons.&lt;br /&gt;
&lt;br /&gt;
In this article I will showcase how we can build Nginx with Lua inside Docker. There are two ways to do it&lt;br /&gt;
&lt;br /&gt;
1. OpenResty&lt;br /&gt;
OpenRestry® is a full-fledged web platform that integrates the standard Nginx core, LuaJIT, many carefully written Lua libraries, lots of high quality 3rd-party Nginx modules&lt;br /&gt;
&lt;br /&gt;
The easiest way to use OpenRestry is to use its docker image&lt;br /&gt;
&lt;br /&gt;
$ docker pull openresty/openresty:alpine-fat&lt;br /&gt;
This image comes with most of the stuff loaded. We are not going to go in depth of this, as we are more interested in building Nginx from source ourself&lt;br /&gt;
&lt;br /&gt;
2. Building Nginx from source&lt;br /&gt;
Building the package from source has some prerequistes like gcc, make and few more things.&lt;br /&gt;
&lt;br /&gt;
Prerequistes&lt;br /&gt;
Centos&lt;br /&gt;
yum install -y wget unzip gcc make openssl-devel pcre-devel zlib-devel&lt;br /&gt;
Ubuntu&lt;br /&gt;
  apt update &lt;br /&gt;
  apt install -y wget unzip make libssl-dev libpcre3-dev gcc make zlib1g-dev&lt;br /&gt;
Alpine&lt;br /&gt;
  apk add --no-cache \&lt;br /&gt;
    ca-certificates \&lt;br /&gt;
    libressl \&lt;br /&gt;
    pcre \&lt;br /&gt;
    zlib \&lt;br /&gt;
    build-base \&lt;br /&gt;
    linux-headers \&lt;br /&gt;
    libressl-dev \&lt;br /&gt;
    pcre-dev \&lt;br /&gt;
    wget \&lt;br /&gt;
    zlib-dev &lt;br /&gt;
Downloading the source&lt;br /&gt;
We need 4 packages to build Nginx with Lua&lt;br /&gt;
&lt;br /&gt;
LuaJIT&lt;br /&gt;
Nginx Source Code&lt;br /&gt;
Nginx Devel Kit&lt;br /&gt;
Nginx Lua Module&lt;br /&gt;
$ mkdir /tmp/nginx&lt;br /&gt;
$ cd /tmp/nginx&lt;br /&gt;
$ wget http://nginx.org/download/nginx-1.13.0.tar.gz&lt;br /&gt;
$ wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz&lt;br /&gt;
$ wget -O nginx_devel_kit.tar.gz https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz&lt;br /&gt;
$ wget -O nginx_lua_module.tar.gz https://github.com/openresty/lua-nginx-module/archive/v0.10.8.tar.gz&lt;br /&gt;
Extract all the tar files&lt;br /&gt;
&lt;br /&gt;
$ tar xvf LuaJIT-2.0.4.tar.gz&lt;br /&gt;
$ tar xvf nginx-1.11.10.tar.gz&lt;br /&gt;
$ tar xvf nginx_devel_kit.tar.gz&lt;br /&gt;
$ tar xvf nginx_lua_module.tar.gz&lt;br /&gt;
Building LuaJIT&lt;br /&gt;
To build Nginx with LuaJIT, we need to build LuaJIT first. This is as simple as a make command&lt;br /&gt;
&lt;br /&gt;
$ cd /tmp/nginx/LuaJIT-2.0.4&lt;br /&gt;
$ make install&lt;br /&gt;
==== Building LuaJIT 2.0.4 ====&lt;br /&gt;
make -C src&lt;br /&gt;
make[1]: Entering directory `/tmp/nginx/LuaJIT-2.0.4/src'&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
ln -sf luajit-2.0.4 /usr/local/bin/luajit&lt;br /&gt;
==== Successfully installed LuaJIT 2.0.4 to /usr/local ====&lt;br /&gt;
Building Nginx&lt;br /&gt;
Next we build configure the Nginx build. We also need to set the environment variables to specifcy the location of the LuaJIT library&lt;br /&gt;
&lt;br /&gt;
$ cd /tmp/nginx/nginx-1.11.10&lt;br /&gt;
$ LUAJIT_LIB=/usr/local/lib LUAJIT_INC=/usr/local/include/luajit-2.0 \&lt;br /&gt;
./configure \&lt;br /&gt;
--user=nobody                          \&lt;br /&gt;
--group=nobody                         \&lt;br /&gt;
--prefix=/etc/nginx                   \&lt;br /&gt;
--sbin-path=/usr/sbin/nginx           \&lt;br /&gt;
--conf-path=/etc/nginx/nginx.conf     \&lt;br /&gt;
--pid-path=/var/run/nginx.pid         \&lt;br /&gt;
--lock-path=/var/run/nginx.lock       \&lt;br /&gt;
--error-log-path=/var/log/nginx/error.log \&lt;br /&gt;
--http-log-path=/var/log/nginx/access.log \&lt;br /&gt;
--with-http_gzip_static_module        \&lt;br /&gt;
--with-http_stub_status_module        \&lt;br /&gt;
--with-http_ssl_module                \&lt;br /&gt;
--with-pcre                           \&lt;br /&gt;
--with-file-aio                       \&lt;br /&gt;
--with-http_realip_module             \&lt;br /&gt;
--without-http_scgi_module            \&lt;br /&gt;
--without-http_uwsgi_module           \&lt;br /&gt;
--without-http_fastcgi_module ${NGINX_DEBUG:+--debug} \&lt;br /&gt;
--with-cc-opt=-O2 --with-ld-opt='-Wl,-rpath,/usr/local/lib' \&lt;br /&gt;
--add-module=/tmp/nginx/ngx_devel_kit-0.3.0 \&lt;br /&gt;
--add-module=/tmp/nginx/lua-nginx-module-0.10.8&lt;br /&gt;
$ make install&lt;br /&gt;
$ nginx -t&lt;br /&gt;
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok&lt;br /&gt;
nginx: configuration file /etc/nginx/nginx.conf test is successful&lt;br /&gt;
Note: We have used Nginx 1.11.10 instead of the latest 1.13.0 because a open issue 1051 with nginx lua module&lt;br /&gt;
&lt;br /&gt;
Now let put the Nginx Lua to a test.&lt;br /&gt;
&lt;br /&gt;
Nginx Lua Testing&lt;br /&gt;
We will build a simple lua endpoint http://localhost/sum?a=&amp;lt;num&amp;gt;&amp;amp;b=&amp;lt;num&amp;gt;, which sums two numbers passed through the url get parameters&lt;br /&gt;
&lt;br /&gt;
location /sum {&lt;br /&gt;
  content_by_lua_block {&lt;br /&gt;
    local args = ngx.req.get_uri_args();&lt;br /&gt;
    ngx.say(args.a + args.b)&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
Insert the above lines of code in the \etc\nginx\nginx.conf inside the server block. Then start nginx in background&lt;br /&gt;
&lt;br /&gt;
$ nginx &amp;amp;&lt;br /&gt;
$ curl &amp;quot;http://localhost/sum/?a=10&amp;amp;b=20&amp;quot;&lt;br /&gt;
30&lt;br /&gt;
For building the same in centos, ubuntu or alpine please follow my code in the tarunlalwani/nginx-lua-docker repository&lt;/div&gt;</summary>
		<author><name>Busk</name></author>
	</entry>
</feed>