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

后端 未结 4 548
一向
一向 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:43

    You can also use the nginx mirror module and poxy_pass it to a web script that runs whatever, in my case I just added this to my main site location {...

    mirror /mirror;
    mirror_request_body off;
    

    and then a new location called mirror that I had run a php script that executed whatever...

    location = /mirror {
        internal;
        proxy_pass http://localhost/run_script.php;
        proxy_pass_request_body off;
        proxy_set_header Content-Length "";
        proxy_set_header X-Original-URI $request_uri;
    }
    

    https://nginx.org/en/docs/http/ngx_http_mirror_module.html

提交回复
热议问题