More precisely can I configure Nginx to output the log entry to a separate log file whenever a particular url is requested? Later the number of lines in that log can give me the download count.
nginx.conf
error_log /home/webadmin/applegrew.com/error-n.log;
events {
worker_connections 1000;
}
http {
include mime.types;
index index.html index.htm index.php index.shtml;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
keepalive_timeout 5;
gzip on;
server {
server_name cink.applegrew.com;
access_log /var/log/cink.applegrew.com/access.log main;
error_log /var/log/cink.applegrew.com/error.log;
root /var/www/cink.applegrew.com/html;
location = /js/cink\.compiler\.min\.js$ {
access_log /var/log/cink.applegrew.com/download-compiler-min.log main;
}
location = /js/cink\.renderer\.min\.js$ {
access_log /var/log/cink.applegrew.com/download-renderer-min.log main;
}
location = /js/cink\.combined\.min\.js$ {
access_log /var/log/cink.applegrew.com/download-combined-min.log main;
}
location /js/src/ { #This works
access_log /var/log/cink.applegrew.com/download-src.log main;
}
include cacheCommon.conf;
}
}
cacheCommon.conf
location ~* \.(?:ico|css|js|gif|jpe?g|png|txt|xml)$ {
# Some basic cache-control for static files to be sent to the browser
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
this probably would work in your nginx vhost for the site
where the /path/to/file.ext is relative to your webroot
Could you please post the full configuration file?
Another way is use
grep -c
:UPDATE
$
at the end or use~
instead of=
.$
means the end of line in RegEx, so you must use the~
prefix.This should work