Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you pass POST and GET to a script through LUA on nginx?

Tags:

nginx

lua

I'm trying to create a webhook in nginx that will pass the POST and GET variables through to a bash script. So far, I've got the below working:

location /webhook {
    if ($request_method != POST) {
        return 405;
    }
    content_by_lua 'os.execute("/opt/bin/webhook.sh arg1 arg2")';
}

However, I'm not sure how to pass the POST and GET parameters through. I've searched online and the only thing I can find is the use of os.execute without parameters or some detailed use of the request body that assumes the user already understands everything you can do with LUA.

Any guidance on how to do this? Thanks!

like image 272
Fmstrat Avatar asked Jan 20 '26 18:01

Fmstrat


1 Answers

You should take a look at ngx.req.get_uri_args and ngx.req.get_post_args.

That said, calling os.execute inside the handler is probably not the best idea, since the handler should be non-blocking.

like image 164
Michal Kottman Avatar answered Jan 22 '26 11:01

Michal Kottman