Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NGinx - Count requests for a particular URL pattern

Tags:

nginx

I wanted to count the number of requests to a particular url pattern. Not sure how this is done in NGinx.

Is this possible:

When an request to the url pattern comes, we serve that request first. Then NGinx makes another request asynchronously to a server which counts the impression. NGinx does not wait for the response of this request.

Thanks.

like image 865
Akshay Rawat Avatar asked Mar 23 '12 15:03

Akshay Rawat


2 Answers

You can use the post_action directive to trigger a sub_request after the main request is complete.

Useful for the sort of logging you have in mind.

** OCT 2016 UPDATE **

The post_action directive has been removed from the Nginx documentation and while it still appears to work, usage is inadvisable. Caveat Emptor!

** JAN 2020 UPDATE **

The Mirror Module, introduced in Nginx 1.13.4, essentially replicates the post_action directive.

like image 168
Dayo Avatar answered Oct 17 '22 08:10

Dayo


You may try this module

https://github.com/theromis/ngx_counter_zone

very close to your request

like image 38
Roman Vasilyev Avatar answered Oct 17 '22 07:10

Roman Vasilyev