Questions tagged [lua-ngx-module]

The lua-nginx-module embeds the Lua interpreter or LuaJIT 2 into the nginx core and integrates the powerful Lua threads (aka Lua coroutines) into the Nginx event model by means of cosockets and Nginx subrequests.

Unlike Apache's mod_lua and Lighttpd's mod_magnet, Lua code executed using this module can be 100% non-blocking on network traffic as long as the Nginx API for Lua provided by this module is used to handle requests to upstream services such as MySQL, PostgreSQL, Memcached, Redis, or upstream HTTP web services.

GitHub/Documentation: https://github.com/openresty/lua-nginx-module

7 questions
4
votes
2 answers

ngx lua: scope of local variable, init in init_by_lua_block

I'm new to nginx lua, and got a setup from previous developer. Trying to go through the docs to understand the scope but I'm pretty unsure. It's like this right now init_by_lua_block { my_module = require 'my_module' …
Luan Nguyen
  • 134
  • 1
  • 7
2
votes
0 answers

how to http request with Lua when Nginx start and restart

I am using Lua Nginx module in my nginx server. I have a Lua script which is execute by init_worker_by_lua_file in nginx.conf so the script will execute when nginx start and restart. What the Lua script does is, it request rest api to some server…
thirdwave
  • 75
  • 1
  • 7
1
vote
1 answer

Kong API Gateway - Reading request body in custom plugin

I am trying to read the request body in a custom plugin by following this url local data = kong.request.get_body() if data then kong.log(data) end I am getting the following error 2019/03/14 21:57:55 [error] 14039#0: *45 lua entry…
navin
  • 165
  • 1
  • 12
1
vote
1 answer

Use NGINX to replace body from proxy_pass

I am new to openresty/nginx and am trying to replace the body the comes from an earlier call to proxy_pass with code like this: body_filter_by_lua_block { ngx.arg[1] = '{"count"' .. ":2}' ngx.arg[2] = true } I had originally, not had the line…
Jake Pearson
  • 27,069
  • 12
  • 75
  • 95
0
votes
0 answers

Why does error_page not work with ngx.location.capture?

I have the following nginx config which purpose is to check connectivity to upstream: location @error { echo "problems"; } location /test { proxy_pass http://2.2.2.2:2222/; # invalid upstream proxy_intercept_errors off; error_page…
deevroman
  • 99
  • 1
  • 2
  • 14
0
votes
1 answer

Return a boolean from lua nginx module's set_by_lua_block method

I'm using lua nginx module in my nginx conf file. I'm trying to set a value variable during runtime depending on some injected parameters. However, I can not return a boolean from the block without converting it into a string. I'm trying to optimize…
Sankalp
  • 1,182
  • 2
  • 17
  • 22
0
votes
0 answers

I need to iterate user-data in Lua

I am reading the ngnix client certificate and storing it in a local variable. local client_cert = openssl_x509.new(ngx.var.ssl_client_raw_cert) local subject = client_cert:getSubject() I need to get the common name from the subject, how can I get…
subrat padhi
  • 151
  • 1
  • 2
  • 11