Documentation Index
Fetch the complete documentation index at: https://launchdarkly-preview.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This guide explains how to use our Lua server-side SDK with the NGINX OpenResty framework. OpenResty extends NGINX with LuaJIT, enabling complex control of NGINX functionality. The OpenResty framework has substantial commercial adoption. Find a basic Dockerized app in the GitHub repository at hello-nginx.Prerequisites
To complete this guide, you must have the following prerequisites:- Basic working knowledge of the LaunchDarkly Lua server-side SDK
- Basic working knowledge of the LaunchDarkly C++ server-side SDKThe C++ server-side SDK is required because the Lua server-side SDK is implemented as a wrapper around the C++ server-side SDK.
Preparing the Lua server-side SDKMake the source of the Lua SDK accessible to Open
RESTY. You can control imports with thelua_package_path directive.
For example:
Preparing the C++ server-side SDKMake the source of the C++ server-side SDK accessible to the dynamic linker. The most convenient way to do this is to install the binary system-wide at /usr/lib/libldserverapi.so.
OpenResty handles OpenSSL in specific ways. You may need to build the SDK from scratch instead of using our release artifacts in order to make OpenSSL work correctly.
Ensuring correct initialization
The most important part of effective SDK usage is managing the lifetime of clients correctly. Because NGINX utilizes process-based concurrency, multiple clients initiate. If you accidentally initiate a client per request the application will be substantially slower, as the SDK has to download a fresh ruleset from LaunchDarkly. Initialize each NGINX worker process exactly once for ideal operations. You can do this with theinit_worker_by_lua_file directive. This directive executes a script when a process is freshly spawned. Client initialization should reside in this script. In the example below, this file is called shared.lua.Here is an example of initialization logic: