nginx - How to run a shell script on every request?

后端 未结 4 541
一向
一向 2020-12-04 13:18

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

4条回答
  •  温柔的废话
    2020-12-04 13:34

    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")
      } 
    }
    

提交回复
热议问题