Convert Figma logo to code with AI

openresty logoopenresty

High Performance Web Platform Based on Nginx and LuaJIT

12,993
1,571
12,993
307

Top Related Projects

26,708

The official NGINX Open Source repository.

3,675

Mirror of Apache HTTP Server. Issues: http://issues.apache.org

11,085

H2O - the optimized HTTP/1, HTTP/2, HTTP/3 server

62,388

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

54,416

The Cloud Native Application Proxy

Quick Overview

OpenResty is a full-fledged web platform that integrates the standard Nginx core, LuaJIT, many Nginx 3rd-party modules, and most of their external dependencies. It is designed to help developers easily build scalable web applications, web services, and dynamic web gateways.

Pros

  • High performance and low resource consumption due to its event-driven architecture
  • Extensibility through Lua scripting, allowing for complex server-side logic
  • Built-in caching mechanisms for improved response times
  • Large ecosystem of modules and community support

Cons

  • Steep learning curve, especially for those unfamiliar with Nginx or Lua
  • Configuration can be complex for advanced use cases
  • Limited Windows support (primarily designed for Unix-like systems)
  • Debugging can be challenging due to the mix of Nginx and Lua

Code Examples

  1. Simple "Hello, World!" server:
server {
    listen 80;
    location / {
        content_by_lua_block {
            ngx.say("Hello, World!")
        }
    }
}
  1. Accessing request headers:
location /headers {
    content_by_lua_block {
        local headers = ngx.req.get_headers()
        for k, v in pairs(headers) do
            ngx.say(k .. ": " .. v)
        end
    }
}
  1. Making an HTTP request:
location /proxy {
    content_by_lua_block {
        local http = require "resty.http"
        local httpc = http.new()
        local res, err = httpc:request_uri("http://example.com")
        if res then
            ngx.say(res.body)
        else
            ngx.say("Error: ", err)
        end
    }
}

Getting Started

  1. Install OpenResty (Ubuntu example):

    wget -qO - https://openresty.org/package/pubkey.gpg | sudo apt-key add -
    sudo apt-get update
    sudo apt-get -y install openresty
    
  2. Create a simple configuration file (e.g., nginx.conf):

    worker_processes  1;
    events {
        worker_connections  1024;
    }
    http {
        server {
            listen 8080;
            location / {
                content_by_lua_block {
                    ngx.say("Hello, OpenResty!")
                }
            }
        }
    }
    
  3. Start OpenResty:

    openresty -p `pwd`/ -c nginx.conf
    
  4. Visit http://localhost:8080 in your browser to see the result.

Competitor Comparisons

26,708

The official NGINX Open Source repository.

Pros of nginx

  • Lightweight and efficient, focusing on core web server and reverse proxy functionality
  • Simpler configuration for basic use cases
  • More widespread adoption and community support

Cons of nginx

  • Limited built-in scripting capabilities
  • Requires external modules for advanced functionality
  • Less flexibility for complex application logic without additional components

Code Comparison

nginx configuration:

server {
    listen 80;
    server_name example.com;
    location / {
        proxy_pass http://backend;
    }
}

OpenResty configuration:

server {
    listen 80;
    server_name example.com;
    location / {
        content_by_lua_block {
            ngx.say("Hello from OpenResty!")
        }
    }
}

Key Differences

  • OpenResty integrates Lua scripting directly into nginx, allowing for more complex logic within the server configuration
  • nginx focuses on core web server functionality, while OpenResty extends these capabilities with additional modules and scripting support
  • OpenResty provides a more comprehensive platform for building web applications and APIs, whereas nginx is primarily used as a web server and reverse proxy

Use Cases

  • Choose nginx for simple web serving and reverse proxy needs
  • Opt for OpenResty when requiring advanced scripting, complex application logic, or building API gateways
3,675

Mirror of Apache HTTP Server. Issues: http://issues.apache.org

Pros of httpd

  • Widely adopted and battle-tested web server with extensive documentation
  • Supports a vast array of modules for extended functionality
  • Strong focus on security with regular updates and patches

Cons of httpd

  • Can be resource-intensive, especially for high-concurrency scenarios
  • Configuration can be complex and verbose for advanced setups
  • Less performant in handling dynamic content compared to more modern alternatives

Code Comparison

httpd configuration example:

<VirtualHost *:80>
    ServerName example.com
    DocumentRoot /var/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

OpenResty configuration example:

server {
    listen 80;
    server_name example.com;
    root /var/www/html;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
}

OpenResty, built on NGINX and LuaJIT, offers high performance and low resource usage, making it ideal for high-concurrency scenarios. It provides a more streamlined configuration syntax and excels at handling dynamic content through its embedded Lua scripting. However, httpd remains a solid choice for traditional web hosting needs, offering robust security features and a wide range of modules for various use cases.

11,085

H2O - the optimized HTTP/1, HTTP/2, HTTP/3 server

Pros of H2O

  • Faster performance, especially for static file serving and SSL/TLS connections
  • Lower memory footprint, making it more suitable for resource-constrained environments
  • Built-in HTTP/2 support without additional modules

Cons of H2O

  • Less extensive ecosystem and third-party module support compared to OpenResty
  • Steeper learning curve for developers familiar with Nginx-based systems
  • Limited Lua scripting capabilities, which are more robust in OpenResty

Code Comparison

H2O configuration example:

hosts:
  "example.com":
    listen:
      port: 443
      ssl:
        certificate-file: /path/to/cert.pem
        key-file: /path/to/key.pem
    paths:
      "/":
        file.dir: /path/to/docroot

OpenResty configuration example:

server {
    listen 443 ssl;
    server_name example.com;
    ssl_certificate /path/to/cert.pem;
    ssl_certificate_key /path/to/key.pem;
    location / {
        root /path/to/docroot;
    }
}

Both H2O and OpenResty offer high-performance web serving capabilities, but they cater to different use cases. H2O excels in raw performance and efficiency, while OpenResty provides a more flexible and extensible platform for building complex web applications with Lua scripting.

62,388

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Pros of Caddy

  • Automatic HTTPS with Let's Encrypt integration
  • Easy configuration with a simple JSON-based format
  • Built-in HTTP/3 support

Cons of Caddy

  • Less performant for high-concurrency scenarios
  • More limited ecosystem and plugin availability
  • Fewer advanced features for complex routing and caching

Code Comparison

Caddy configuration:

{
  "apps": {
    "http": {
      "servers": {
        "example": {
          "listen": [":80"],
          "routes": [
            {
              "handle": [{
                "handler": "static_response",
                "body": "Hello, World!"
              }]
            }
          ]
        }
      }
    }
  }
}

OpenResty configuration:

http {
    server {
        listen 80;
        location / {
            content_by_lua_block {
                ngx.say("Hello, World!")
            }
        }
    }
}

Both OpenResty and Caddy offer powerful web server capabilities, but they cater to different use cases. OpenResty excels in performance and flexibility, leveraging the Nginx core with Lua scripting. Caddy, on the other hand, focuses on simplicity and modern features like automatic HTTPS. The choice between them depends on specific project requirements and developer preferences.

54,416

The Cloud Native Application Proxy

Pros of Traefik

  • Easy configuration with automatic service discovery
  • Built-in support for modern cloud-native architectures and microservices
  • Dynamic configuration updates without restarts

Cons of Traefik

  • Less performant for high-traffic scenarios compared to OpenResty
  • Limited Lua scripting capabilities
  • Steeper learning curve for advanced customizations

Code Comparison

OpenResty configuration example:

http {
    server {
        listen 80;
        location / {
            content_by_lua_block {
                ngx.say("Hello, OpenResty!")
            }
        }
    }
}

Traefik configuration example:

http:
  routers:
    my-router:
      rule: "Host(`example.com`)"
      service: my-service
  services:
    my-service:
      loadBalancer:
        servers:
          - url: "http://localhost:8080"

OpenResty excels in performance and flexibility through Lua scripting, making it ideal for complex, high-traffic scenarios. Traefik, on the other hand, shines in modern containerized environments with its automatic service discovery and easy configuration. While OpenResty offers more fine-grained control, Traefik provides a more user-friendly experience for cloud-native deployments.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Name

OpenResty - Turning Nginx into a Full-Fledged Scriptable Web Platform

Table of Contents

Description

OpenResty is a full-fledged web application server by bundling the standard nginx core, lots of 3rd-party nginx modules, as well as most of their external dependencies.

This bundle is maintained by Yichun Zhang (agentzh).

Because most of the nginx modules are developed by the bundle maintainers, it can ensure that all these modules are played well together.

The bundled software components are copyrighted by the respective copyright holders.

The homepage for this project is on openresty.org.

For Users

Visit the download page on the openresty.org web site to download the latest bundle tarball, and follow the installation instructions in the installation page.

For Bundle Maintainers

The bundle's source is at the following git repository:

https://github.com/openresty/openresty

To reproduce the bundle tarball, just do

make

at the top of the bundle source tree.

Please note that you may need to install some extra dependencies, like perl, dos2unix, and mercurial. On Fedora 22, for example, installing the dependencies is as simple as running the following commands:

sudo dnf install perl dos2unix mercurial

Back to TOC

Additional Features

In additional to the standard nginx core features, this bundle also supports the following:

Back to TOC

resolv.conf parsing

syntax: resolver address ... [valid=time] [ipv6=on|off] [local=on|off|path]

default: -

context: http, stream, server, location

Similar to the resolver directive in standard nginx core with additional support for parsing additional resolvers from the resolv.conf file format.

When local=on, the standard path of /etc/resolv.conf will be used. You may also specify arbitrary path to be used for parsing, for example: local=/tmp/test.conf.

When local=off, parsing will be disabled (this is the default).

This feature is not available on Windows platforms.

Back to TOC

Mailing List

You're very welcome to join the English OpenResty mailing list hosted on Google Groups:

https://groups.google.com/group/openresty-en

The Chinese mailing list is here:

https://groups.google.com/group/openresty

Back to TOC

Report Bugs

You're very welcome to report issues on GitHub:

https://github.com/openresty/openresty/issues

Back to TOC

Copyright & License

The bundle itself is licensed under the 2-clause BSD license.

Copyright (c) 2011-2019, Yichun "agentzh" Zhang (章亦春) agentzh@gmail.com, OpenResty Inc.

This module is licensed under the terms of the BSD license.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Back to TOC