OpenResty : OpenResty is a web platform based on nginx which can run Lua scripts using its LuaJIT engine.
This technology is used by 5.16% of websites in the Web servers category. The most popular industry vertical is Business and Finance, with Business being the top subcategory.
What is OpenResty?
OpenResty is a web platform based on Nginx and LuaJIT that transforms Nginx from a web server into a full-fledged application server. Created by Yichun Zhang (agentzh) at Taobao in 2009, OpenResty bundles Nginx with powerful Lua scripting capabilities, enabling dynamic request handling directly within the web server.
Unlike standard Nginx that requires upstream servers for dynamic content, OpenResty executes Lua code at any stage of request processing. This eliminates round-trips to application servers for tasks like authentication, rate limiting, and response transformation. Major users include Cloudflare, Kong, and Alibaba.
OpenResty is the foundation for Kong API Gateway and many edge computing platforms. It combines Nginx's C-based performance with Lua's scripting flexibility. LuaJIT compilation delivers near-native performance for Lua code, making it suitable for high-throughput production workloads.
Industry Vertical Distribution
Technologies Frequently Used with OpenResty
| Technology | Co-usage Rate | Website |
|---|---|---|
| Nginx | 94.53% | http://nginx.org/en |
| Lua | 90.13% | http://www.lua.org |
| jQuery | 47.98% | https://jquery.com |
| Google Analytics | 33.2% | http://google.com/analytics |
| PHP | 29.26% | http://php.net |
| Google Tag Manager | 25.91% | http://www.google.com/tagmanager |
| Google Font API | 23.91% | http://google.com/fonts |
| jQuery Migrate | 21.76% | https://github.com/jquery/jquery-migrate |
| MySQL | 21.55% | http://mysql.com |
| WordPress | 21.46% | https://wordpress.org |
OpenResty Architecture
Nginx Core: OpenResty is built on Nginx's event-driven core. All Nginx modules and configuration directives work unchanged. The Lua integration adds programmability without sacrificing Nginx's performance characteristics.
LuaJIT Integration: ngx_lua module embeds LuaJIT into Nginx workers. Lua code runs in non-blocking coroutines. Each request gets its own Lua execution context with access to request/response APIs.
Request Phases: Lua handlers hook into Nginx phases: rewrite, access, content, header_filter, body_filter, log. Execute custom logic at precise points in request lifecycle. Combine multiple phases for complex workflows.
Shared Memory: lua_shared_dict provides shared memory zones accessible by all workers. Store rate limiting counters, session data, or cached values. Atomic operations prevent race conditions.
Cosockets: Non-blocking socket API for upstream connections. Connect to Redis, MySQL, PostgreSQL, Memcached directly from Lua. Connection pooling eliminates connect overhead.
Libraries: Rich ecosystem including lua-resty-redis, lua-resty-mysql, lua-resty-http, lua-resty-jwt. Most HTTP and database operations available without leaving Nginx.
AI-Powered Technology Recommendations
Our AI recommender engine, trained on 100 million data points, suggests these technologies for websites using OpenResty:
| Technology | AI Score | Website |
|---|---|---|
| Lua | 0.74 | http://www.lua.org |
| Google Cloud CDN | 0.2 | https://cloud.google.com/cdn |
| Google Cloud | 0.19 | https://cloud.google.com |
| Tumblr | 0.14 | http://www.tumblr.com |
| Gentoo | 0.12 | http://www.gentoo.org |
| HSTS | 0.11 | https://www.rfc-editor.org/rfc/rfc6797#section-6.1 |
| core-js | 0.1 | https://github.com/zloirock/core-js |
| Cargo | 0.09 | http://cargocollective.com |
| Tealium | 0.08 | http://tealium.com |
| GoDaddy Domain Parking | 0.08 | https://www.godaddy.com |
IAB Tier 1 Vertical Distribution
Relative Usage by Industry
Market Distribution Comparison
OpenResty Use Cases
API Gateway: Kong, the most popular open-source API gateway, is built on OpenResty. Authentication, rate limiting, request transformation, and logging at the edge. Plugin architecture extends functionality.
Edge Computing: Execute application logic at the edge before reaching origin servers. A/B testing, feature flags, and personalization without backend changes. Cloudflare Workers conceptually similar.
Dynamic Load Balancing: Lua scripts select upstreams based on request attributes. Service discovery integration (Consul, etcd). Circuit breakers and health checks in code.
Web Application Firewall: ModSecurity alternative with Lua rules. Inspect and modify requests/responses. IP reputation, bot detection, and attack blocking.
Authentication Gateway: JWT validation, OAuth flows, and session management at Nginx layer. Offload auth from application servers. Centralized identity verification.
Real-time Analytics: Stream request logs to analytics backends. Aggregate metrics in shared memory. Custom logging formats with dynamic fields.
IAB Tier 2 Subcategory Distribution
Top Websites Using OpenResty
| Website | IAB Category | Subcategory | OpenRank |
|---|---|---|---|
| telegraph.co.uk | Sports | Rugby | 7.22 |
| monash.edu | Business and Finance | College Education | 6.32 |
| wattpad.com | Books and Literature | Fiction | 6.25 |
| chicagotribune.com | News and Politics | International News | 6.14 |
| lanacion.com.ar | News and Politics | International News | 5.74 |
| coindesk.com | News and Politics | Economy | 5.73 |
| softabuse.com | Music and Audio | Rock Music | 5.64 |
| ajc.com | News and Politics | Talk Radio | 5.63 |
| mlive.com | News and Politics | Weather | 5.55 |
| cleveland.com | Music and Audio | Talk Radio | 5.53 |
OpenResty Code Examples
Rate Limiting with Shared Memory
-- nginx.conf
lua_shared_dict rate_limit 10m;
server {
location /api/ {
access_by_lua_block {
local limit = ngx.shared.rate_limit
local key = ngx.var.remote_addr
local requests, err = limit:incr(key, 1, 0, 60)
if requests > 100 then
ngx.status = 429
ngx.say('{"error": "Rate limit exceeded"}')
ngx.exit(429)
end
}
proxy_pass http://backend;
}
}
-- JWT Authentication
location /protected/ {
access_by_lua_block {
local jwt = require "resty.jwt"
local auth_header = ngx.var.http_authorization
if not auth_header then
ngx.exit(401)
end
local token = auth_header:match("Bearer%s+(.+)")
local verified = jwt:verify("secret", token)
if not verified.verified then
ngx.exit(403)
end
ngx.req.set_header("X-User-Id", verified.payload.sub)
}
proxy_pass http://backend;
}
Usage by Domain Popularity (Top 1M)
Usage by Domain Age
The average age of websites using OpenResty is 10.9 years. The average OpenRank (measure of backlink strength) is 2.15.
OpenResty Benefits
Nginx Performance: Maintains Nginx's benchmark-leading performance. LuaJIT compiles to native code. Sub-millisecond Lua execution for most operations.
Programmable Edge: Move application logic to the web server layer. Reduce backend requests. Implement complex routing without upstream servers.
Non-Blocking I/O: Cosocket API provides async database and HTTP connections. No blocking operations stall workers. High concurrency maintained.
Rapid Development: Lua scripting faster than C module development. Hot reload Lua code without restart. Test changes immediately.
Rich Ecosystem: Extensive lua-resty-* library collection. Redis, MySQL, PostgreSQL, HTTP client, JWT, and more. Community maintains production-ready modules.
Battle-Tested: Powers Cloudflare's edge, Kong Gateway, and Alibaba's infrastructure. Proven at massive scale. Active development and security updates.
Nginx Compatibility: All Nginx configuration works unchanged. Add Lua gradually. Existing knowledge transfers directly.
Emerging Websites Using OpenResty
| Website | IAB Category | Subcategory | OpenRank |
|---|---|---|---|
| sycamoretreechurch.com | Hobbies & Interests | Genealogy and Ancestry | 0 |
| lmtgloans.com | Personal Finance | Personal Debt | 0 |
| thatcaptain.com | Events and Attractions | Reggae | 0 |
| fortwashingtonautobody.com | Personal Finance | Insurance | 0 |
| manhattanlawlab.com | Family and Relationships | Law | 0 |
Technologies Less Frequently Used with OpenResty
| Technology | Co-usage Rate | Website |
|---|---|---|
| A-Frame | 0% | https://aframe.io |
| Acquia Cloud Platform | 0% | https://www.acquia.com/products/drupal-cloud/cloud-platform |
| Ada | 0% | https://www.ada.cx |
| Adally | 0% | https://adally.com/ |
| AddShoppers | 0% | http://www.addshoppers.com |
