nginx-如何在每个请求上运行shell脚本? [英] nginx - How to run a shell script on every request?

查看:75
本文介绍了nginx-如何在每个请求上运行shell脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的Nginx服务器每次接收到任何HTTP请求时都运行一个Shell脚本.有任何简单的方法可以做到这一点吗?

I want to run a shell script every time my nginx server receives any HTTP request. Any simple ways to do this?

推荐答案

您可以通过nginx.conf文件中的Lua代码执行Shell脚本来实现此目的.您需要具有 HttpLuaModule 才能做到这一点.

You can execute a shell script via Lua code from the nginx.conf file to achieve this. You need to have the HttpLuaModule to be able to do this.

以下是执行此操作的示例.

Here's an example to do this.

location /my-website {
  content_by_lua_block {
    os.execute("/bin/myShellScript.sh")
  } 
}

这篇关于nginx-如何在每个请求上运行shell脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆