Introduction
OpenResty is a powerful web platform based on NGINX and LuaJIT. It extends NGINX‘s capabilities by integrating a robust scripting environment, making it ideal for developers who want to build high-performance web applications and APIs. If you’re looking to harness OpenResty‘s full potential, you need a proper installation on your Ubuntu system.
This guide will walk you through installing OpenResty on Ubuntu step by step. Whether you’re a beginner or an experienced developer, you’ll find clear instructions and helpful tips to ensure a smooth setup process.
Prerequisites
Before we start, ensure that your Ubuntu system is up to date. Also, make sure you have sudo privileges. Here’s what you need:
- A system running Ubuntu (20.04 or later recommended)
- A user account with sudo privileges
- An active internet connection
To update your system, run the following commands:
sudo apt update && sudo apt upgrade -y
ShellScriptOnce your system is updated, you’re ready to proceed.
Step 1: Install Required Dependencies
OpenResty requires some essential dependencies. Install them using the following command:
sudo apt install -y curl gnupg2 ca-certificates lsb-release software-properties-common
ShellScriptThese packages ensure that your system can securely download and manage software sources.
Step 2: Add the OpenResty Repository
Next, you need to add the official OpenResty repository to your system. This will make it easy to install and update OpenResty.
Run the following commands:
curl -fsSL https://openresty.org/package/pubkey.gpg | sudo gpg --dearmor -o /usr/share/keyrings/openresty.gpg
ShellScriptThen, add the repository:
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
ShellScriptAfter adding the repository, update the package list:
sudo apt update
ShellScriptStep 3: Install OpenResty
Now that the repository is added, you can install OpenResty with:
sudo apt install -y openresty
ShellScriptThis command installs OpenResty along with all necessary dependencies.
Step 4: Verify the Installation
Once the installation is complete, verify that OpenResty is installed correctly by checking its version:
openresty -v
ShellScriptYou should see output similar to:
nginx version: openresty/1.21.4.1
ShellScriptStep 5: Start and Enable OpenResty
To start the OpenResty service, run:
sudo systemctl start openresty
ShellScriptTo enable it at boot:
sudo systemctl enable openresty
ShellScriptCheck the status of the service to ensure it’s running:
sudo systemctl status openresty
ShellScriptIf everything is working, you should see output indicating that OpenResty is active and running.
Step 6: Configure OpenResty
OpenResty’s configuration files are located in /usr/local/openresty/nginx/conf/
. The main configuration file is nginx.conf
. To edit it, use:
sudo nano /usr/local/openresty/nginx/conf/nginx.conf
ShellScriptMake any necessary changes, then save and exit. Restart OpenResty to apply changes:
sudo systemctl restart openresty
ShellScriptStep 7: Test OpenResty
To confirm OpenResty is working correctly, create a simple test page. Open the default web root directory:
sudo nano /usr/local/openresty/nginx/html/index.html
ShellScriptAdd the following content:
<!DOCTYPE html>
<html>
<head>
<title>OpenResty Test</title>
</head>
<body>
<h1>OpenResty is running successfully!</h1>
</body>
</html>
HTMLSave and exit, then restart OpenResty:
sudo systemctl restart openresty
ShellScriptNow, open your web browser and go to http://your_server_ip/
. You should see the test page.
Step 8: Set Up Firewall Rules (Optional)
If you have a firewall enabled, allow HTTP and HTTPS traffic to ensure OpenResty is accessible:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload
ShellScriptConclusion
In this guide, we covered how to install OpenResty on Ubuntu, from setting up dependencies to testing the installation. OpenResty provides a powerful platform for web applications, combining the efficiency of NGINX with the flexibility of LuaJIT.
By following these steps, you now have a fully functional OpenResty installation on your Ubuntu server. Whether you’re using it for APIs, caching, or full-fledged web applications, OpenResty offers exceptional performance and flexibility.
Leave a Reply