Title: OpenResty SSL Setup: Install and Secure Site withNginx with Let&#8217;s Encrypt on Ubuntu
Author: Immanuel Raj
Published: January 17, 2024
Last modified: February 15, 2025

---

![install and configure nginx openresty with ssl on ubuntu](https://immanuelraj.
dev/wp-content/uploads/2024/01/install-and-configure-nginx-openresty-with-ssl-on-
ubuntu.avif)

# OpenResty SSL Setup: Install and Secure Site withNginx with Let’s Encrypt on Ubuntu

[January 17, 2024](https://immanuelraj.dev/nginx-openresty-ssl-setup-ubuntu/)

—

by

[Immanuel Raj](https://immanuelraj.dev/author/iamimmanuelraj/)

in [Linux](https://immanuelraj.dev/category/linux/), [Self Hosting](https://immanuelraj.dev/category/self-hosting/),
[SSL](https://immanuelraj.dev/category/ssl/), [Web](https://immanuelraj.dev/category/web/)

Read Time

2–3 minutes

Securing your website with SSL is crucial for both security and SEO benefits. In
this guide, we’ll walk through the complete process of OpenResty SSL setup, including
how to install OpenResty on Ubuntu, configure SSL using Certbot, and enable auto-
renewal.

---

## **Prerequisites for OpenResty SSL Setup**

Before we begin, ensure you have the following:

 * A **Linux server** (Ubuntu preferred)
 * **Root or sudo access**
 * A **registered domain name** pointing to your server

## **Step 1: Install OpenResty on Ubuntu**

OpenResty is an extended version of Nginx that includes powerful scripting capabilities.
Follow the official OpenResty [installation guide](https://openresty.org/en/) to
install it on your Ubuntu server.

## **Step 2: Install Certbot for OpenResty Nginx SSL**

Certbot is an automated tool for obtaining SSL certificates from Let’s Encrypt.

To install Certbot, run:

    ```wp-block-code
    sudo apt update
    sudo apt install certbot -y
    ```

## **Step 3: Obtain an SSL Certificate for OpenResty HTTPS Configuration**

Run the following command to generate an SSL certificate for your domain:

    ```wp-block-code
    sudo certbot certonly --standalone --preferred-challenges http -d example.com
    ```

Replace `example.com` with your actual domain name.

Once completed, your SSL certificates will be located in:

    ```wp-block-code
    /etc/letsencrypt/live/example.com/
    ```

## **Step 4: Configure Nginx OpenResty SSL Settings**

Now, update your Nginx OpenResty configuration to use the SSL certificate.

Open your configuration file:

    ```wp-block-code
    sudo nano /usr/local/openresty/nginx/conf/nginx.conf
    ```

### **Nginx OpenResty HTTPS Configuration**

Add the following server block inside the `http` block:

    ```wp-block-code
    server {
        listen 443 ssl;
        server_name example.com;

        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_ciphers HIGH:!aNULL:!MD5;

        location / {
            root /var/www/html;
            index index.html;
        }
    }
    ```

Save and exit (Ctrl + X, then Y, then Enter).

## **Step 5: Restart OpenResty Nginx for SSL to Take Effect**

Restart Nginx OpenResty for the changes to take effect:

    ```wp-block-code
    sudo systemctl restart openresty
    ```

If Nginx OpenResty is not set up as a service, you may need to start it manually:

    ```wp-block-code
    sudo /usr/local/openresty/nginx/sbin/nginx
    ```

## **Step 6: Auto-Renew OpenResty SSL Certificate with Certbot**

Let’s Encrypt certificates expire every 90 days, so setting up auto-renewal is important.

Add the following cron job to renew the certificate automatically:

    ```wp-block-code
    sudo crontab -e
    ```

Add this line at the end:

    ```wp-block-code
    0 0 * * * certbot renew --quiet && systemctl reload openresty
    ```

This will check and renew the certificate daily at midnight.

## **Conclusion**

Your Nginx OpenResty server is now secured with SSL! You’ve successfully completed
the OpenResty SSL setup, installed Nginx OpenResty, configured SSL with Certbot,
and set up auto-renewal for your certificates. Now, your website can securely serve
content over HTTPS.

For further reading, check out:

 * [OpenResty Official Documentation](https://openresty.org/en/)
 * [Certbot’s Documentation](https://certbot.eff.org/)

If you have any questions or face issues, feel free to drop a comment below!

[certbot](https://immanuelraj.dev/tags/certbot/) [linux](https://immanuelraj.dev/tags/linux/)
[nginx](https://immanuelraj.dev/tags/nginx/) [openresty](https://immanuelraj.dev/tags/openresty/)
[ssl](https://immanuelraj.dev/tags/ssl/) [ubuntu](https://immanuelraj.dev/tags/ubuntu/)

[Previous:  Step-by-Step Guide to Configuring Nginx and PHP-FPM on Ubuntu](https://immanuelraj.dev/nginx-and-php-fpm-setup/)

[Next:  The Philosophy and History of Linux](https://immanuelraj.dev/the-philosophy-and-history-of-linux/)

![Immanuel Raj Avatar](https://secure.gravatar.com/avatar/88db6e1fa27cf854075acbaa156189ace30cf3701b2d8640cd774280ead1d4d3?
s=80&d=mm&r=g)

## About the author

Software Developer & Technology Consultant

---

## Popular Categories

 * [Bible](https://immanuelraj.dev/category/bible/) (1)
 * [Cloudflare](https://immanuelraj.dev/category/cloudflare/) (1)
 * [Databases](https://immanuelraj.dev/category/databases/) (1)
 * [Docker](https://immanuelraj.dev/category/docker/) (1)
 * [Email](https://immanuelraj.dev/category/email/) (1)
 * [ERPNext](https://immanuelraj.dev/category/erpnext/) (3)
 * [Frappe](https://immanuelraj.dev/category/frappe/) (2)
 * [Github Actins](https://immanuelraj.dev/category/github-actins/) (1)
 * [God](https://immanuelraj.dev/category/god/) (1)
 * [Google Cloud](https://immanuelraj.dev/category/gcp/) (1)
 * [Hosting](https://immanuelraj.dev/category/hosting/) (2)
 * [Life](https://immanuelraj.dev/category/life/) (1)
 * [Linux](https://immanuelraj.dev/category/linux/) (13)
 * [ML](https://immanuelraj.dev/category/ml/) (1)
 * [Networking](https://immanuelraj.dev/category/networking/) (2)
 * [Security](https://immanuelraj.dev/category/security/) (2)
 * [Self Hosting](https://immanuelraj.dev/category/self-hosting/) (7)
 * [SSL](https://immanuelraj.dev/category/ssl/) (3)
 * [Terminal](https://immanuelraj.dev/category/terminal/) (1)
 * [Tools](https://immanuelraj.dev/category/tools/) (2)
 * [Uncategorized](https://immanuelraj.dev/category/uncategorized/) (8)
 * [Web](https://immanuelraj.dev/category/web/) (2)
 * [WordPress](https://immanuelraj.dev/category/wordpress/) (1)

---

## Useful Links

Links I found useful and wanted to share.

 * [Sponsor Me](https://github.com/sponsors/iamimmanuelraj)

---

## Search the website

Search