DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Coding
  3. Languages
  4. Supercharging NGINX With Lua: Part I

Supercharging NGINX With Lua: Part I

Sometimes, we need more complex workflows invoked on a per-request basis. A NGINX LUA module exists that allows us to inject our own Lua handlers into the traffic flow.

Vic van Gool user avatar by
Vic van Gool
·
Jan. 20, 17 · Opinion
Like (1)
Save
Tweet
Share
3.73K Views

Join the DZone community and get the full member experience.

Join For Free

NGINX is a really really fantastic piece of software. It is supremely flexible and handles all kinds of traffic orchestration workloads. One place that NGINX has received commentary, however, is in its handling of branching logic.

Sometimes, it is necessary to have more complex workflows invoked on a per-request basis, however. Luckily, a NGINX Lua module exists that allows us to simply inject our own Lua handlers into the traffic flow. Lua is a great fit as an embedded language because of its size, simplicity and JIT-compiled speed.

Getting Lua for NGINX

Unfortunately, adding the Lua module to NGINX on your own requires compilation of the module, which itself requires some tricky dependencies:

  • Lua JIT.
  • NGINX Development Kit.
  • NGINX source.
  • Knowledge of compatibilities.

The good news is that you don't need to compile it yourself! There is a well-maintained project provided by OpenResty that bundles it all up for you. Follow the installation instructions here.

Ubuntu Install Cheatsheet

Because you cannot currently download a packaged version of OpenResty NGINX for Ubuntu, you need to compile it from the source. Here is a little helper to get you started!

sudo su  
version=1.11.2.2

# install dependencies
apt-get install libreadline-dev libncurses5-dev libpcre3-dev   libssl-dev perl make build-essential

# download & untar
curl -s -o openresty-$version.tar.gz https://openresty.org/download/openresty-$version.tar.gz  
tar -xvf openresty-$version.tar.gz  
cd openresty-$version

# configure & make
./configure --with-pcre-jit --with-ipv6 --with-stream --with-http_realip_module --with-http_stub_status_module --prefix=/opt/openresty 
make -j8  
make install

# NOTE: installs openresty to: /opt/openresty)
# NOTE: installs nginx to: /opt/nginx/openresty/nginx)

Next Steps

Part II of this series will illustrate some examples of how we can now make use of our brand new supercharged NGINX-with-Lua to do some custom request handling.

Lua (programming language)

Published at DZone with permission of Vic van Gool, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Memory Debugging: A Deep Level of Insight
  • How to Configure AWS Glue Job Using Python-Based AWS CDK
  • Why It Is Important To Have an Ownership as a DevOps Engineer
  • Handling Virtual Threads

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: