十三、Nginx静态文件不记录日志和过期时间
nginx 服务器日志文件占用空间很大,里面记录了一个页面的访问,而且还记录了访问这些页面返回的一些静态资源,比如css,js,图片这些,怎么样才能不让他记录这些东西,而只是记录访问了哪些页面?
1、修改虚拟主机配置文件
# vi /usr/local/nginx/conf/vhost/first.conf
增加如下内容:
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ //匹配脱义静态文件
{
expires 7d; //配置过期时间
access_log off;
}
location ~ .*\.(js|css)$ //匹配js,css文件
{
expires 12h;
access_log off;
}
2、测试语法及重新加载配置
# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
# /usr/local/nginx/sbin/nginx -s reload
3、使用curl测试,对比后会发现访问test.gif没有被记录至日志
# cd /data/www/default
#touch test.gif
# curl -x127.0.0.1:80 first.com/test.gif