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

查看:31
本文介绍了如何在每个请求上运行 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")
  } 
}

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

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