Making Sense of The Infinite

Unlocking Infinite Possibilities Through Curiosity

How to Install OpenResty on Ubuntu: A Complete Guide

Introduction

OpenResty is a powerful web platform based on NGINX and . It extends ‘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 ‘s full potential, you need a proper installation on your system.

This guide will walk you through installing OpenResty on Ubuntu step by step. Whether you’re a beginner or an experienced , 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 connection

To update your system, run the following commands:

sudo apt update && sudo apt upgrade -y
ShellScript

Once 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
ShellScript

These packages ensure that your system can securely download and manage 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
ShellScript

Then, 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
ShellScript

After adding the repository, update the package list:

sudo apt update
ShellScript

Step 3: Install OpenResty

Now that the repository is added, you can install OpenResty with:

sudo apt install -y openresty
ShellScript

This 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
ShellScript

You should see output similar to:

nginx version: openresty/1.21.4.1
ShellScript

Step 5: Start and Enable OpenResty

To start the OpenResty service, run:

sudo systemctl start openresty
ShellScript

To enable it at boot:

sudo systemctl enable openresty
ShellScript

Check the status of the service to ensure it’s running:

sudo systemctl status openresty
ShellScript

If everything is working, you should see output indicating that OpenResty is active and running.

Step 6: Configure OpenResty

OpenResty’s 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
ShellScript

Make any necessary changes, then save and exit. Restart OpenResty to apply changes:

sudo systemctl restart openresty
ShellScript

Step 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
ShellScript

Add the following content:

<!DOCTYPE html>
<html>
<head>
    <title>OpenResty Test</title>
</head>
<body>
    <h1>OpenResty is running successfully!</h1>
</body>
</html>
HTML

Save and exit, then restart OpenResty:

sudo systemctl restart openresty
ShellScript

Now, 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 enabled, allow HTTP and HTTPS traffic to ensure OpenResty is accessible:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw reload
ShellScript

Conclusion

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.

Last revised on

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *