Mark Ku's Blog
Podcast ConversationAI dialogue version of this article · Mandarin audio
Audio for this article is powered by VoAIVoAI

OpenResty and Kong: A First Look at the High-Performance Web Platform and API Gateway

When building websites and APIs today, performance and flexibility are top concerns. OpenResty is Nginx + Lua scripting — it goes beyond static proxying so you can flexibly handle all sorts of needs. Kong is an API Gateway built on OpenResty, used by many startups and large companies alike. This article is a casual walkthrough of OpenResty and Kong, plus how to debug them in containers.

What is OpenResty?

In short: OpenResty is Nginx + Lua. You can write scripts to extend functionality — API Gateway, reverse proxy, even a WAF (Web Application Firewall) — no problem.

What's so great about OpenResty?

  • Super high performance: Nginx is already fast; add Lua scripts and you get flexibility plus speed.
  • Easy to extend: edit a Lua script and reload — no recompilation.
  • Big ecosystem: many ready-made Lua modules — auth, caching, API management, etc.
  • Versatile: API Gateway, reverse proxy, WAF, log collection — all doable.

Who is it for?

  • Teams wanting a high-performance API Gateway or reverse proxy
  • Engineers who want to extend Nginx quickly with Lua
  • Folks doing microservices and DevOps

What can you build with OpenResty?

  • API Gateway
  • Dynamic websites
  • Reverse proxy and load balancing
  • WAF (Web Application Firewall)
  • Log and monitoring collection

Kong: an API Gateway built on OpenResty

Kong uses OpenResty under the hood, then modularizes API management, auth, and traffic control. Adding features means installing a plugin — super convenient.

What makes Kong special?

  • Pluggable: features as plugins — add what you need.
  • High performance: built on OpenResty/Nginx — speed isn't a question.
  • Distributed and cloud-native: runs on K8s and Docker — very flexible.
  • Active community: plenty of folks online to discuss issues with.

How does Kong relate to OpenResty?

Kong takes OpenResty's flexibility to the limit, so you don't have to write Lua to handle most API Gateway needs.

How do you debug OpenResty and Kong?

  1. Check the Error Log
    • Usually at /usr/local/openresty/nginx/logs/error.log or /var/log/nginx/error.log
    • Good for: initial debugging
  2. Enable Debug Log
    • Kong: set log_level = debug in kong.conf
    • OpenResty: set error_log ... debug; in nginx.conf
    • Good for: seeing finer execution flow
  3. Add log calls in Lua scripts
    • ngx.log(ngx.ERR, "Debug info: ", cjson.encode(var))
    • Good for: tracing variables and flow
  4. API testing
    • Use Postman/curl to call APIs and inspect responses
    • Good for: validating plugins, routes, auth
  5. Plugin ordering
    • Kong's plugins have order — wrong order behaves weirdly
  6. Official docs / community

Remote debugging in containers (Docker)

  1. Get inside the container and tail logs
    docker exec -it openresty-container /bin/sh
    tail -f /usr/local/openresty/nginx/logs/error.log
    
  2. View container logs directly
    docker logs -f openresty-container
    
  3. Mount a local directory
    docker run -v /your/local/logs:/usr/local/openresty/nginx/logs ... openresty
    
  4. Capture traffic
    sudo tcpdump -i docker0 port 8080
    
  5. VSCode Remote - Containers
    • Edit and debug files inside the container directly from VSCode — super convenient

Common debugging tips

  • Bad nginx.conf (test with nginx -t)
  • Container network not connected
  • Lua script bugs or missing modules
  • Wrong plugin order

Closing

OpenResty supercharges Nginx, and Kong takes API Gateway to the next level. If you have API management, traffic control, or auth needs, both tools are well worth a spin. When issues come up, lean on logs and the community — debugging isn't hard!

Questions? Drop a comment — let's level up together!

Author

Mark Ku

擁有 10+ 年經驗的資深軟體工程師,現為 AI 應用 Builder,專注於大型平台架構與簡化複雜系統設計,從電商系統到訂閱與收費平台,結合 AI Agent、AI 整合與自動化開發,打造高效率且可持續演進的產品技術基礎。Read More

Found this useful?

The author's free tools, daily podcasts and newsletter are all here.

Mark Ku · This article is licensed under CC BY 4.0. Credit the author and link back to the original when reusing it.

Comments

Subscribe to Newsletter

Subscribe to get new posts delivered instantly — never miss a tech share.

By submitting, you agree to receive emails. You can anytime.

Popular Posts

View all
Mark Ku
··602

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution

Oracle Cloud Always Free Tier: Linux Host and Static IP for a $0 Cloud Solution
Mark Ku
··490

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.

Say Goodbye to Postman's Fee Trap! A Hands-on Guide to Bruno, the Open-Source Git-Native API Testing Powerhouse.
Mark Ku
··333

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki

A Free, Open-Source, Notion-like Knowledge Base — A Complete Guide to Deploying and Backing Up Outline Wiki
Mark Ku
··264

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning

Training Your Own AI Voice: Hardware Requirements, Open-Source Model Comparison, and LoRA Fine-Tuning
Mark Ku
··221

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1

Building an Efficient API Management Platform: Deploying Kong Gateway from Scratch - Part 1
Mark Ku
··215

Setting Up Samba on Ubuntu to Share Folders with Windows 11

Setting Up Samba on Ubuntu to Share Folders with Windows 11
OpenResty 與 Kong:高效能 Web 平台與 API Gateway 初探 - Mark Ku's Tech Notes