Objective
Build a single, fully static OpenResty binary on Linux that includes:
- LuaJIT for scripting
- SQLite support (via LuaJIT FFI or a custom C module)
- No SSL/OpenSSL dependencies
- No dynamic libraries — everything self-contained
The result should be portable, minimal, and deployable in environments without external dependencies.
Prerequisites
Build Environment
- Linux
x86_64(or ARM if cross-compiling) - Standard build tools:
gcc,make,autoconf,automake,libtool - Minimal utilities:
wgetorcurl,tar,gzip
Required Sources
- OpenResty source (latest stable)
- LuaJIT source (bundled with OpenResty or latest standalone)
- SQLite source (latest amalgamation:
sqlite3.c+sqlite3.h) - PCRE source (regex support for Nginx)
- zlib source (HTTP compression)
Note: Exclude OpenSSL and any SSL-related modules.
High-Level Build Steps
1) Prepare Sources
Download, extract, and organize sources for OpenResty, LuaJIT, SQLite, PCRE, and zlib.
2) Build Static Dependencies
- Compile PCRE and zlib as static libraries (
.a) with PIC disabled. - Compile SQLite from the amalgamation into a single static library.
3) Configure OpenResty
- Use OpenResty
./configure. - Point to static PCRE, zlib, and SQLite libraries.
- Disable SSL-related modules (
http_ssl_module,http_v2_module). - Ensure LuaJIT is compiled statically (default for OpenResty).
4) Customize Nginx Modules
- Include only necessary built-ins (HTTP,
stub_status, gzip). - Exclude any modules requiring dynamic libraries or SSL.
5) Adjust Linker Flags
- Force static linking of all libraries.
- Include SQLite, zlib, PCRE, and LuaJIT objects in the final link.
- Ensure no shared libraries are referenced.
6) Compile OpenResty
- Run
maketo produce a single binary. - Verify with
lddthat no dynamic dependencies remain.
7) Integrate SQLite Access
- Lua scripts: use LuaJIT FFI to call SQLite functions from the static library.
- Optionally: create a minimal C module wrapping SQLite into a Lua API.
- Ensure SQLite objects are linked into the OpenResty binary.
8) Testing
- Run the binary in a clean environment.
- Execute a Lua script that creates an SQLite DB, performs queries, and returns results via HTTP.
- Verify the binary works without external libraries.
Detailed Considerations
LuaJIT Integration
- OpenResty bundles LuaJIT by default.
- Ensure JIT is enabled during compilation.
- Compile LuaJIT as part of the static OpenResty binary; avoid shared
.sofiles.
SQLite Integration
- Use the amalgamation build (
sqlite3.c+sqlite3.h). - Compile into a static object/library.
- Access from Lua via FFI for direct DB calls.
- Alternatively, provide a Lua C module compiled into OpenResty.
Dependency Management
- PCRE: required for regex in Nginx configs; build statically.
- zlib: required for gzip compression; build statically.
- OpenSSL: excluded; ensure all SSL-requiring modules are disabled.
Nginx Module Selection
Include minimal modules for:
- Core HTTP processing
- Logging
- URL rewriting
- Gzip compression
- LuaJIT integration
Exclude:
http_ssl_modulehttp_v2_module- Any third-party modules requiring dynamic libraries
Build Validation
Confirm the final binary is fully static:
ldd /path/to/openresty→ should report “not a dynamic executable”.file /path/to/openresty→ confirms static linking.
Test SQLite:
- Write a Lua script to create a DB, insert rows, and query data.
- Serve via OpenResty to ensure LuaJIT FFI calls work.
Test HTTP server:
- Serve a simple page with Lua content.
- Ensure gzip compression works.
- Verify SSL is not active (no OpenSSL dependency).
Outcome
- Single, self-contained OpenResty binary
- LuaJIT fully embedded
- SQLite fully embedded and accessible from Lua
- No SSL or OpenSSL dependencies
- Portable and suitable for minimal Linux environments