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

时间:2021-09-06
本文章向大家介绍Nginx静态文件不记录日志和过期时间,主要包括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的访问记录日志

原文地址:https://www.cnblogs.com/antong/p/15234141.html