0

I have an nginx server running on ubuntu server. I have many websites and hundreds of pages hosted on the server. I want to execute one PHP function on each page when it is requested by a user. It is not feasible to add/call that function on all the websites and each & every page manually.

Is there a way in nginx where I can define which PHP file/function it should execute before serving the request to a user?

1 Answer 1

1

NGINX does not have this capacity as part of stock NGINX functions. This is something that needs to happen at the PHP level - which is not nginx - if it has to run for every request it has to be done at PHP or the PHP application.

You may be able to do this with some type of Lua code done by the third-party Lua module (which must be manually compiled in, unless you use nginx-extras) that passes a request before processing to PHP backend but that will be executed separately from the sites and their web app items, quite possibly earlier than you want it to (I am not an expert in the Lua module and its functionality though).

This is NOT however a typical use case so such preprocessing of requests is not part of the design spec for nginx and possibly not easy to accomplish via the Lua module either.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .