Apache 自定义日志格式可跟踪完整的文件下载
我正在尝试编写一个奖励系统,如果用户下载完整的文件,他们将获得奖励积分,那么我的日志格式应该是什么。
经过大量搜索后,这是我第一次理解,之前从未做过自定义日志。
首先,我应该编辑哪个文件来自定义日志,因为我找不到这个东西。我正在使用带有默认 apache、php5 和 mysql 安装的 ubuntu 服务器
# I use this commands and they work fine
nano /etc/apache2/apache2.conf
/etc/init.d/apache2 restart
我认为这就是我需要为我的目的做的
LogLevel notice
LogFormat "%f %u %x %o" rewards
CustomLog /var/www/logs/rewards_log rewards
这是因为它是命令还是缺少某些东西?是否有任何特定位置需要添加此内容?
还有一件事 %o
是针对发送的文件大小的,是否可以仅记录特定目录中的文件?或者对于大小超过 10mb 的文件。
谢谢。
I am trying to write a reward system wherein users will be given reward points if they download complete files, So what should be my log format.
After searching alot this is what I understand its my first time and havent done custom logs before.
First of all which file should I edit for custom logs because this thing I cant find. I am using ubuntu server with default apache, php5 and mysql installation
# I use this commands and they work fine
nano /etc/apache2/apache2.conf
/etc/init.d/apache2 restart
I think this is what I need to do for my purpose
LogLevel notice
LogFormat "%f %u %x %o" rewards
CustomLog /var/www/logs/rewards_log rewards
This is as it is command or there is something missing? and is there any particular location where I need to add this?
and one more thing %o
is for filesize that was sent and is it possible to log only files from a particular directory? or for files with size more than 10mb.
Thank You.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看
/etc/apache2/apache2.conf
,您应该能够找到日志指令,例如LogLevel
等。请注意,这些设置对于整个 Apache 安装是全局的。CustomLog 指令只能针对每个服务器/虚拟主机进行设置(请参阅范围此处)。
要使用
CustomLog
指令,您还必须加载 apache 的mod_log
模块。这可以使用a2enmod
命令来完成。问候,
延斯
Have a look in
/etc/apache2/apache2.conf
and you should probably be able to find the log directives such asLogLevel
and others. Note that those settings are global for your whole Apache installation.The
CustomLog
directive can only be set per server/virtual host basis (see scope here).To use the
CustomLog
directive you must also load themod_log
module for apache. This can be done with thea2enmod
command.Regards,
Jens
似曾相识:
如何使用 apache 日志检查完整文件下载
检查 mod_log_config 手册:大小写很重要 - 应该是 %X 和 %O,而不是 %x 和 %o。仅当您使用基本的 http 身份验证(这是一个非常糟糕的主意)时,%u 才会起作用,如果您必须采用此方法,则使用(可选加密的)用户名删除 cookie,并在日志文件中使用 %C 将其读回。
更好的解决方案是将文件访问包装在 PHP 脚本中。
Deja vu:
How to use apache logs to check complete file downloads
Check manual for mod_log_config: case is important - that should be %X and %O not %x and %o. %u will only work if you are using basic http authentication (which is a very bad idea) drop a cookie with the (optionally encrypted) username and read it back with %C in your log file if you must take this approach.
A better soluton would be to wrap the file access in a PHP script.