
現在做網站、API,大家都很在意效能跟彈性,OpenResty 就是用 Nginx 加上 Lua 腳本,讓你不只做靜態代理,還能很彈性地處理各種需求,Kong 則是直接用 OpenResty 打造的 API Gateway,很多新創或大公司都在用。這篇就用比較口語的方式,帶你快速認識 OpenResty 跟 Kong,還有怎麼在容器裡 debug。
簡單說,OpenResty 就是 Nginx 加上 Lua,可以寫腳本擴充功能,你想要 API Gateway、反向代理、甚至做 WAF(Web 防火牆)都沒問題。
Kong 就是用 OpenResty 做底層,然後把 API 管理、認證、流量控管都模組化,你要加功能就裝 plugin,超方便。
Kong 就是把 OpenResty 的彈性發揮到極致,讓你不用自己寫 Lua,也能很快搞定 API Gateway 需求。
/usr/local/openresty/nginx/logs/error.log
或 /var/log/nginx/error.log
kong.conf
設 log_level = debug
nginx.conf
設 error_log ... debug;
ngx.log(ngx.ERR, "Debug info: ", cjson.encode(var))
docker exec -it openresty-container /bin/sh tail -f /usr/local/openresty/nginx/logs/error.log
docker logs -f openresty-container
docker run -v /your/local/logs:/usr/local/openresty/nginx/logs ... openresty
sudo tcpdump -i docker0 port 8080
nginx -t
測)OpenResty 讓 Nginx 變超強,Kong 又把 API Gateway 做到極致。你只要有 API 管理、流量控管、認證需求,這兩套工具真的很值得玩玩看。遇到問題多看 log、多用社群,debug 也不難!
有問題歡迎留言討論,大家一起進步!