Install and Configure OpenResty on Ubuntu 24.04

By Raman Kumar

Updated on Nov 04, 2025

In this tutorial, we'll learn how to install and configure OpenResty on Ubuntu 24.04.

Introduction

Modern web applications demand high performance, low latency, and the flexibility to run custom logic as close to the edge as possible. Traditional web servers are great for serving static content, but they fall short when we need advanced traffic control, request inspection, API routing, caching, authentication, or dynamic response handling. This is where OpenResty becomes a powerful choice for developers and businesses that want more control over their web stack.

What is OpenResty?

OpenResty is a full-featured web platform built on top of Nginx that allows us to run Lua scripts directly inside the Nginx event-driven architecture. Instead of relying on external application servers, OpenResty enables us to process requests, apply logic, and generate responses at the Nginx level with minimal overhead.

Prerequisites

Before we begin, ensure we have the following:

  • An Ubuntu 24.04 on dedicated server or KVM VPS.
  • Basic Linux Command Line Knowledge.
  • A domain name pointing A record to server IP.

Install and Configure OpenResty on Ubuntu 24.04

Step 1: Update the Server

We start by updating our Ubuntu system to ensure all packages are fresh.

sudo apt update && sudo apt upgrade -y

Step 2: Install Basic Dependencies

Install required tools before adding the OpenResty repository.

sudo apt install -y curl wget gnupg ca-certificates lsb-release

Step 3: Add the Official OpenResty Repository

This adds the OpenResty APT source so we install the latest stable version.

wget -O - https://openresty.org/package/pubkey.gpg | sudo gpg --dearmor -o /usr/share/keyrings/openresty.gpg

echo "deb [signed-by=/usr/share/keyrings/openresty.gpg] http://openresty.org/package/ubuntu $(lsb_release -sc) main" \
| sudo tee /etc/apt/sources.list.d/openresty.list

sudo apt update

Step 4: Install OpenResty

sudo apt install -y openresty

Once done, start and enable the service:

sudo systemctl enable --now openresty
sudo systemctl status openresty

OpenResty is now running.

Step 5: Check Installation

Run the command below to confirm installation:

openresty -V

Step 6: Understand Where Files Are Located

OpenResty stores files in these main locations:

Purpose Path

  • Main Nginx config   /usr/local/openresty/nginx/conf/nginx.conf
  • Site configs    /usr/local/openresty/nginx/conf/conf.d/
  • Web files   /usr/local/openresty/nginx/html/
  • Logs    /usr/local/openresty/nginx/logs/

Step 7: Create a Simple Lua Test Page

Let’s create a small page to confirm Lua is working inside OpenResty.

Create a config file:

sudo mkdir -p /usr/local/openresty/nginx/conf/conf.d
sudo nano /usr/local/openresty/nginx/conf/conf.d/test.conf

Add this:

server {
    listen 80;
    server_name _;

    location / {
        default_type text/plain;
        content_by_lua_block {
            ngx.say("OpenResty is working with Lua!")
        }
    }
}

Save the file, then test and reload:

sudo openresty -t
sudo systemctl reload openresty

Now open the server IP in a browser and we should see the message.

Step 8: Install Lua Modules (Optional but Useful)

If we want to add extra Lua features, we can use OPM (OpenResty Package Manager).

Example: install the HTTP client module

sudo /usr/local/openresty/bin/opm get SkyLothar/lua-resty-jwt

Step 9: Enable Firewall Access

If the firewall is enabled, allow web traffic.

sudo ufw allow 80
sudo ufw allow 443

Step 10: Host test website

To host test website, we need to create a configuration file:

sudo tee /usr/local/openresty/nginx/conf/conf.d/brb.conf >/dev/null <<'EOF'
server {
    listen 80;
    server_name example.com;

    location / {
        default_type text/plain;
        return 200 "Hello World";
    }
}
EOF

Note: Replace example.com with your domain name.

Test Configuration & Reload

sudo openresty -t && sudo systemctl reload openresty

Test in Browser

Visit:

http://example.com

Step 11: Basic Troubleshooting Commands

These commands help when something goes wrong:

sudo openresty -t          # Check for errors
sudo systemctl reload openresty
sudo systemctl restart openresty
sudo tail -f /usr/local/openresty/nginx/logs/error.log

Summary

We now have:

  • OpenResty installed on Ubuntu 24.04
  • Lua running inside Nginx
  • A working test page
  • Optional module support