Answer the question
In order to leave comments, you need to log in
How to count the number of times an image has been accessed using nginx?
Gentlemen, I dug around this morning and did not find anything intelligible. It is required to display statistics on access to pictures, pictures in the EU but in statics and I would not want to issue them using scripts. How do smart people count the number of hits to static content? I have already looked at log parsers like wiki.nginx.org/NginxHttpLogRequestSpeed , but something tells me that this is not the best way to solve the problem.
There is such a module wiki.nginx.org/HttpEchoModule#echo_exec but I don’t know about the speed of work. In general, who had similar problems, share the solutions. Thank you in advance for your response!
Answer the question
In order to leave comments, you need to log in
Yes, a normal way with log parsing. Get a separate log for pictures and read it.
The solution with x_accel_redirect will spawn a bunch of constant cgi processes, and this is a big load on the system.
It is better to have one daemon process hanging in the system, which monitors the output of the `tail -f /var/log/access.log` command and writes to the database in real time.
Pay attention to Scribe
Scribe is a server for aggregating log data streamed in real time from a large number of servers. It is designed to be scalable, extensible without client-side modification, and robust to failure of the network or any specific machine.
We had a slightly different task, but I agree with the opinion above. It's best to parse the logs. With the help of syslog-ng, we redirected the necessary logs to the central server, where a small daemon parses the logs and enters data into the database. Very comfortable.
hint - nginx does not know how to push data to syslog. But syslog-ng can monitor an arbitrary log file
cat /var/log/nginx-log-from-pictures-with-sections | grep anything | wc -l
Especially for any counters, there was a post_action directive that allows you to specify what will be launched after the request is completed. There you can connect the built-in pearl, memcache, fastsgi, anything for smart calculation. But if you request frequently, then hang a special log on the pictures in a format convenient for parsing and parse it once every X minutes. This is ideal from a load point of view. There is also an option with built-in variables, but it hurts a lot
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question