Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug lua code inside nginx config?

I want to insert log points (io.write) inside my lua code which itself is in nginx configuration (using HttpLuaModule for nginx). How to do that? Access and error logs are not showing them.

like image 416
mannuscript Avatar asked Oct 04 '14 03:10

mannuscript


People also ask

How does Lua work with Nginx?

Nginx+Lua is a self-contained web server embedding the scripting language Lua. Powerful applications can be written directly inside Nginx without using cgi, fastcgi, or uwsgi. By adding a little Lua code to an existing Nginx configuration file, it is easy to add small features.

Does Nginx support Lua?

Some older versions of Nginx don't support native loading of Lua modules. Therefore, we require Nginx to be built with Lua and LuaJIT support.


1 Answers

When running under nginx, you should use ngx.log. E.g:

ngx.log(ngx.STDERR, 'your message here')

For a working example, see http://linuxfiddle.net/f/77630edc-b851-487c-b2c8-aa6c9b858ebb

For documentation, see http://wiki.nginx.org/HttpLuaModule#ngx.log

like image 156
mikaraento Avatar answered Sep 30 '22 22:09

mikaraento