Nginx静态文件不记录日志和过期时间

Nginx静态文件不记录日志和过期时间

静态文件不记录日志和过期时间

1.修改虚拟主机配置文件

server
{
    listen 80;
    server_name test.com test1.com test2.com;
    index index.html index.htm index.php;
    root /data/wwwroot/test.com;
    if ($host != ‘test.com‘ ) {
        rewrite  ^/(.*)$  http://test.com/$1  permanent;
    }
    location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$   //\.为脱意字符,用来匹配点字符
    {
          expires      7d;
          access_log off;
    }
    location ~ .*\.(js|css)$
    {
          expires      12h;
          access_log off;
    }

    access_log /tmp/test.com.log test;
}
[root@antong ~]# /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
[root@antong ~]# /usr/local/nginx/sbin/nginx -s reload
2.模拟一个图像文件
[root@antong ~]# vim /data/wwwroot/test.com/1.jpg
[root@antong ~]# vim /data/wwwroot/test.com/2.js
3.测试
[root@antong ~]# curl -x127.0.0.1:80 test.com/1.jpg
adasd
[root@antong ~]# curl -x127.0.0.1:80 test.com/2.js
sdasd
[root@antong ~]# curl -x127.0.0.1:80 test.com/index.html
test.com
[root@antong ~]# curl -x127.0.0.1:80 test.com/2.jshad
<html>
<head><title>404 Not Found</title></head>
<body>
<center><h1>404 Not Found</h1></center>
<hr><center>nginx/1.17.8</center>
</body>
</html>
[root@antong ~]# cat /tmp/test.com.log                  
127.0.0.1 - [06/Sep/2021:03:54:57 -0400] test.com "/index.html" 200 "-" "curl/7.29.0"
127.0.0.1 - [06/Sep/2021:03:57:25 -0400] test.com "/2.jshad" 404 "-" "curl/7.29.0"
//没有记录1.jpg和2.js的访问记录日志

Nginx静态文件不记录日志和过期时间

上一篇:kafka 0.10.0.1 源码编译 之感


下一篇:ListView 基础列表组件、水平 列表组件、图标组件