OpenResty® is a full-featured web platform that uses our improved Nginx core to scale online applications and services. Its purpose is to make it simple for developers to create scalable web applications, web services, and dynamic web gateways. OpenResty modules allow you to write Lua code that runs directly in a Nginx worker, allowing you to create high-performance applications. The OpenResty solution’s goal is to operate a server-side web app entirely in the nginx server, taking use of the nginx event model to do non-blocking I/O not just with HTTP clients, but also with distant backends such as MySQL, PostgreSQL, Memcached, and Redis.
In today’s guide, we are going to learn how to install OpenResty web platform on Ubuntu / Debian Linux system.
Features of OpenResty Web Platform
Below are the features of OpenResty web platform:
- OpenResty® has a wide range of real-world applications, including dynamic web portals and web gateways.
- Mobile apps, advertising, distributed storage, and data analytics are all supported by web service platforms.
- Firewalls for web applications.
- When using lua-tablepool, reject the items when the pool size exceeds the max pool size for improved performance.
- For the stream subsystem, the ngx.process API API was implemented.
- The get ctx table function now allows utilizing the caller’s ctx table, which reduces the cost of generating a new ctx table.
- OpenResty® is run on a variety of hardware, from large metals to small embedded devices with low resources.
- The goal of OpenResty® is to entirely execute your server-side web program on the Nginx server.
- OpenResty® successfully transforms the nginx server into a sophisticated web app server that supports the Lua programming language.
- Introduce the LUAJIT TEST FIXED ORDER macro for traversing lua tables in fixed order.
Install OpenResty Web Platform on Ubuntu
Follow the steps below to install OpenResty on Ubuntu.
Step 1: Stop and Disable Nginx
If nginx is already installed and operating, disable and stop it before installing openresty as described below, or the installation may fail:
sudo systemctl disable nginx && sudo systemctl stop nginx
Step 2: Import GPG Key and add APT repository
We should add GPG public keys to install some requirements:
sudo apt -y install --no-install-recommends wget gnupg ca-certificates
wget -O - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
For x86 64 or amd64 systems, use the following commands to add APT repository:
echo "deb http://openresty.org/package/ubuntu $(lsb_release -sc) main"| sudo tee /etc/apt/sources.list.d/openresty.list
Also, for systems based on the arm64 or aarch64 architectures:
echo "deb http://openresty.org/package/arm64/ubuntu $(lsb_release -sc) main"| sudo tee /etc/apt/sources.list.d/openresty.list
Step 3: Install OpenResty Web Platform
Now update the APT index:
sudo apt update -y
Install package openresty:
sudo apt -y install openresty
After successful install, you can check if openresty is active and running:
$ systemctl status openresty.service
● openresty.service - The OpenResty Application Platform
Loaded: loaded (/lib/systemd/system/openresty.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2025-02-21 09:17:40 UTC; 2min 42s ago
Process: 5123 ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 5134 ExecStart=/usr/local/openresty/nginx/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 5135 (nginx)
Tasks: 2 (limit: 2344)
Memory: 2.7M
CGroup: /system.slice/openresty.service
├─5135 nginx: master process /usr/local/openresty/nginx/sbin/nginx -g daemon on; master_process on;
└─5136 nginx: worker process
Feb 21 09:17:40 ubuntu-noble systemd[1]: Starting The OpenResty Application Platform...
Feb 21 09:17:40 ubuntu-noble systemd[1]: Started The OpenResty Application Platform.
Install OpenResty Web Platform on Debian
To install OpenResty on Debian 12 and 11 follow the steps below:
Step 1: Stop and disable nginx
Use the following commands to stop and disable nginx service:
sudo systemctl disable nginx
sudo systemctl stop nginx
Step 2: Install dependencies
Install required prerequisites:
sudo apt-get -y install --no-install-recommends wget gnupg ca-certificates
Step 3: Import GPG key and add APT repository
Import GPG key using the following command:
wget -O - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
For x86 64 or amd64 systems, use the following commands to add the repository:
codename=`grep -Po 'VERSION="[0-9]+ \(\K[^)]+' /etc/os-release`
echo "deb http://openresty.org/package/debian $codename openresty"|sudo tee /etc/apt/sources.list.d/openresty.list
Also, for systems based on the arm64 or aarch64 hardware platforms:
codename=`grep -Po 'VERSION="[0-9]+ \(\K[^)]+' /etc/os-release`
echo "deb http://openresty.org/package/arm64/debian $codename openresty"|sudo tee /etc/apt/sources.list.d/openresty.list
Step 4: Install OpenResty Web Platform
Update the APT index:
sudo apt update
Then install OpenResty packages on Debian 11 / Debian 12:
sudo apt -y install openresty
Configure OpenResty on Ubuntu / Debian
Step 1: Creating an OpenResty Service
We’re going to set up OpenResty as a service so that it begins automatically when the computer boots up. We’ll use the systemd
init service to do this.
Create a new OpenResty systemd file first:
sudo vim /etc/systemd/system/openresty.service
Then change the default Nginx systemd
file for OpenResty by copying it from a fresh installation:
# Stop dance for OpenResty
# A modification of the Nginx systemd script
# =======================
#
# ExecStop sends SIGSTOP (graceful stop) to the Nginx process.
# If, after 5s (--retry QUIT/5) OpenResty is still running, systemd takes control
# and sends SIGTERM (fast shutdown) to the main process.
# After another 5s (TimeoutStopSec=5), and if OpenResty is alive, systemd sends
# SIGKILL to all the remaining processes in the process group (KillMode=mixed).
#
# Nginx signals reference doc:
# http://nginx.org/en/docs/control.html
#
[Unit]
Description=A dynamic web platform based on Nginx and LuaJIT.
After=network.target
[Service]
Type=forking
PIDFile=/run/openresty.pid
ExecStartPre=/usr/local/openresty/bin/openresty -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/local/openresty/bin/openresty -g 'daemon on; master_process on;'
ExecReload=/usr/local/openresty/bin/openresty -g 'daemon on; master_process on;' -s reload
ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/openresty.pid
TimeoutStopSec=5
KillMode=mixed
[Install]
WantedBy=multi-user.target
In the above systemd file, we have the following:
Unit
After=network.target
causes OpenResty to start after the network has been established, allowing it to bind and listen to ports. It may now be accessed from the outside.
Service
Type=forking
notifies systemd that the service will be started in the background by the process we call in ExecStart, and that the process will afterwards terminate itself.PIDFile=/run/openresty.pid
instructs systemd where to look for the PID file that OpenResty generates when it starts up. This informs systemd whether OpenResty is still active.ExecStartPre=/usr/local/openresty/bin/openresty -t -q -g 'daemon on; master process on;'
invokes the OpenResty script but does not start it. The -t flag informs OpenResty that we just want it to test the configuration file; the -q flag tells it to conceal any non-error output; the -g flag turns on the global directives daemon; master process on tells OpenResty that we want it to run as a daemon in the background. This script is run as ExecStartPre so that systemd does not try to start OpenResty if the configuration file is incorrect, as this command would fail.- OpenReesty is started using
ExecStart=/usr/local/openresty/bin/openresty -g 'daemon on; master process on;'
. Without the -t option, this is the same as ExecStartPre. - When we execute systemctl reload openresty, the command
ExecReload=/usr/local/openresty/bin/openresty -g 'daemon on; master process on;' -s reload
tells systemd to run this command. OpenResty is told to refresh its configuration file with the -s parameter. ExecStop=-/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/openresty.pid
When OpenResty is stopped, instructs systemd to perform this command. It sends SIGSTOP to the PID file’s listed processes. If it’s still running after 5 seconds, systemd will take over using one of the two methods below.TimeoutStopSec=5
instructs systemd to terminate the process in 5 seconds. If OpenRest does not end on its own, systemd will try to stop it forcibly.- When OpenResty does not cease after 5 seconds,
KillMode=mixed
defines how systemd should try to kill it.
Install section
WantedBy=multi-user.target
If the service is configured to start at boot, this tells systemd when we want it to start. multi-user. target indicates that the service will only be launched if a multi-user system has been started, allowing us to execute OpenResty as a separate user.
The OpenResty Nginx configuration file must then be customized.
First, open the configuration file:
sudo vim /usr/local/openresty/nginx/conf/nginx.conf
Delete everything before the events
line and add the following three lines in its place:
user www-data;
worker_processes auto;
pid /run/openresty.pid;
events {
worker_connections 1024;
}
. . .
This file ensures that we’re operating as the www-data
user and that systemd
can detect OpenResty’s presence thanks to the pid line that OpenResty will generate once it begins.
Now, create the log directory:
sudo mkdir /var/log/openresty
Restart the systemd service to allow it to locate our file:
sudo systemctl daemon-reload
Start OpenResty with systemd now:
sudo systemctl start openresty
Then enable OpenResty:
sudo systemctl enable openresty
Ensure that OpenResty is active and running:
$ systemctl status openresty
● openresty.service - A dynamic web platform based on Nginx and LuaJIT.
Loaded: loaded (/etc/systemd/system/openresty.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2025-02-21 10:48:42 UTC; 2h 17min ago
Main PID: 856 (nginx)
Tasks: 2 (limit: 2344)
Memory: 8.9M
CGroup: /system.slice/openresty.service
├─856 nginx: master process /usr/local/openresty/nginx/sbin/nginx -g daemon on; master_process on;
└─859 nginx: worker process
Feb 21 10:48:32 ubuntu-focal systemd[1]: Starting The OpenResty Application Platform...
Feb 21 10:48:42 ubuntu-focal systemd[1]: Started The OpenResty Application Platform.
Step 2: Open HTTP and HTTPS Ports in your Firewall
For the web server to operate, you must now accept HTTP and HTTPS connections across your firewall.
sudo ufw allow http
sudo ufw allow https
sudo ufw reload
Running Application on OpenResty
We are going run Hello World inour OpenResty web platform.
The resty script included with OpenResty is the easiest way to produce a Hello World output to the console. Run the following command on the command line, for example:
$ resty -e 'print("Hello World")'
Hello World
Running HelloWorld on Web Browser
Step 1: Create Directory Layout
We’ll start by making a new directory for our experiments. You can use any directory you like. To keep things simple, we’ll just use ~/openrestytest
:
mkdir ~/openrestytest
cd ~/openrestytest
mkdir logs/ conf/
Step 2: Create the Nginx.conf Config File
Create a plain text file called conf/nginx.conf
:
sudo vim conf/nginx.conf
Add the following contents to the file created above:
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http {
server {
listen 8080;
location / {
default_type text/html;
content_by_lua_block {
ngx.say("<p>Hello World</p>")
}
}
}
}
Step 3: Start the Nginx server
Using our config file, start the nginx server as follows:
nginx -p `pwd`/ -c conf/nginx.conf
Step 4: Access our Hello World web service
Curl may be used to connect to our new web service, Hello World:
$ curl http://localhost:8080/
<p>Hello World</p>
You may easily navigate to http://<your ip-address>:8080/
using your preferred web browser.
Conclusion
Our guide on how to install OpenResty web platform on Ubuntu and Debian has come to a conclusion. OpenResty is a great way to execute your web apps. We hope you found this information useful.
Amazing guides on our site: