LNMP--Nginx不记录指定文件日志
2015-08-12 10:01
561 查看
编辑Nginx配置文件:
[root@LampLinux ~]# vim /usr/local/nginx/conf/nginx.conf
找到下面一行:
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
'$host "$request_uri" $status'
'"$http_referer" "$http_user_agent"';
将内容更改为:
log_format linan '$remote_addr $http_x_forwarded_for [$time_local]'
'$host "$request_uri" $status'
'"$http_referer" "$http_user_agent"';
编辑虚拟主机配置文件:
[root@LampLinux ~]# vim /usr/local/nginx/conf/vhosts/test.conf
在 “root /data/www” 下面写入:
access_log /tmp/access.log linan; (红字用户名对应上面更改后的用户名)
检查并重加载:
[root@LampLinux ~]# /usr/local/nginx/sbin/nginx -t
[root@LampLinux ~]# /usr/local/nginx/sbin/nginx -s reload
刷新网页,我们查看日志:
[root@LampLinux ~]# cat /tmp/access.log
发现记录了很多内容,其中图片信息没有必要去记录。
配置不记录指定文件日志:
编辑虚拟主机配置文件:
[root@LampLinux ~]# vim /usr/local/nginx/conf/vhosts/test.conf
在"用户认证"配置下面写入:
location ~ .*\.(gif|jpg|png|jpeg|bmp|swf)$
{
access_log off;
}
[root@LampLinux ~]# /usr/local/nginx/sbin/nginx -t
[root@LampLinux ~]# /usr/local/nginx/sbin/nginx -s reload
刷新网页,继续查看日志:
[root@LampLinux ~]# cat /tmp/access.log
发现没有限制记录的图片了,但是还有js和css类型的图片没有禁止记录。
下面我们去配置,还是进入“虚拟主机配置文件”编辑,在上一段下面继续补充一段:
location ~ (static|cache) # 限定static和cache,因为日志中观察到css和js都在这个目录下。
{
access_log off;
}
[root@LampLinux ~]# /usr/local/nginx/sbin/nginx -t
[root@LampLinux ~]# /usr/local/nginx/sbin/nginx -s reload
刷新网页,查看日志:
[root@LampLinux ~]# cat /tmp/access.log
不记录限制的图片文件了。
[root@LampLinux ~]# vim /usr/local/nginx/conf/nginx.conf
找到下面一行:
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
'$host "$request_uri" $status'
'"$http_referer" "$http_user_agent"';
将内容更改为:
log_format linan '$remote_addr $http_x_forwarded_for [$time_local]'
'$host "$request_uri" $status'
'"$http_referer" "$http_user_agent"';
编辑虚拟主机配置文件:
[root@LampLinux ~]# vim /usr/local/nginx/conf/vhosts/test.conf
在 “root /data/www” 下面写入:
access_log /tmp/access.log linan; (红字用户名对应上面更改后的用户名)
检查并重加载:
[root@LampLinux ~]# /usr/local/nginx/sbin/nginx -t
[root@LampLinux ~]# /usr/local/nginx/sbin/nginx -s reload
刷新网页,我们查看日志:
[root@LampLinux ~]# cat /tmp/access.log
发现记录了很多内容,其中图片信息没有必要去记录。
配置不记录指定文件日志:
编辑虚拟主机配置文件:
[root@LampLinux ~]# vim /usr/local/nginx/conf/vhosts/test.conf
在"用户认证"配置下面写入:
location ~ .*\.(gif|jpg|png|jpeg|bmp|swf)$
{
access_log off;
}
[root@LampLinux ~]# /usr/local/nginx/sbin/nginx -t
[root@LampLinux ~]# /usr/local/nginx/sbin/nginx -s reload
刷新网页,继续查看日志:
[root@LampLinux ~]# cat /tmp/access.log
发现没有限制记录的图片了,但是还有js和css类型的图片没有禁止记录。
下面我们去配置,还是进入“虚拟主机配置文件”编辑,在上一段下面继续补充一段:
location ~ (static|cache) # 限定static和cache,因为日志中观察到css和js都在这个目录下。
{
access_log off;
}
[root@LampLinux ~]# /usr/local/nginx/sbin/nginx -t
[root@LampLinux ~]# /usr/local/nginx/sbin/nginx -s reload
刷新网页,查看日志:
[root@LampLinux ~]# cat /tmp/access.log
不记录限制的图片文件了。
相关文章推荐
- Powershell Profiles配置文件的存放位置介绍
- PowerShell入门教程之创建和使用配置文件实例
- SERV-U 的配置文件详解
- php.ini 配置文件的深入解析
- redis2.8配置文件中文翻译版
- C#实现线程安全的简易日志记录方法
- PHP配置文件php.ini中打开错误报告的设置方法
- JS基于cookie实现来宾统计记录访客信息的方法
- C#中读取App.config配置文件代码实例
- 用VBS记录客户机操作的代码
- c++实现逐行读取配置文件写入内存的示例
- 从数据库中读取记录横向排列
- 关于session在PHP5的配置文件中的详细设置参数说明
- MySQL 配置文件my.cnf 例子最详细翻译
- apache 配置文件解说
- Android 读取Properties配置文件的小例子
- PHP 配置文件中open_basedir选项作用
- .net 读取非标准配置文件的小例子
- APACHE 配置文件中文版 httpd.conf FOR Apache 2.2.13
- 读取spring配置文件的方法(spring读取资源文件)