OpenResty® Scalable Web Platform by Extending NGINX with Lua


Yichun Zhang , 06 Oct 2013 (created 06 Oct 2013)

You should always check out Nginx's error log file (specified by the error_log directive in nginx.conf) for any errors or warnings.

If you prefer redirecting common Lua errors to the HTTP response body during Lua development, you can put a Lua pcall call on the top level of your Lua code to catch and redirect any Lua exceptions. But keep in mind, not all errors can be captured this way because you could have errors when sending out the response, then it is impossible to put such errors into the response body.

During Lua code development, you can disable the Lua code cache temporarily so that you do not have to reload the Nginx server for your (external) Lua code changes to take effect.

Also, it is strongly recommended to follow the test-driven development workflow. For example, Lua Resty Redis Library uses the Test::Nginx test scaffold to drive its (declarative) test suite.

If you are on Linux, there are quite many real-time analysing tools based on systemtap, which can be used to inspect a running Nginx worker process in various ways:

You can find additional tools in the stap++ project:

These tools can not only debug functional problems, but also profile online servers to find performance bottlenecks.