Nginx的日志优化

1、日志轮询切割:

  这篇文章已经对日志轮询切割做个介绍:请点击这里

2、不记录不需要的日志

  在实际的工作中,对于负载均衡器健康节点检查或某些特定文件的日志,一般不需要记录下来,因为统计PV是按照页面计算的,而且日志的写入频繁会消耗大量的I/O,降低服务器的性能。我们要对不需要记录的日志做不记录。配置如下:

  在虚拟主机的配置文件中进行配置:(红色部分为添加或修改部分)以虚拟主机www.brian.com为例

[root@Nginx www_date]# cat brian.conf 
    server {
        listen       80;
        server_name  www.brian.com;
        location / {
            root   html/brian;
            index  index.html index.htm;
        auth_basic    "brian training";
        auth_basic_user_file  /opt/nginx/conf/htpasswd;
            
        }
    location ~ .*\.(js|jpg|JPG|jpeg|JPEG|css|bmp|gif|GIF)$ {
        access_log off;                            # 添加过滤不记录日志的策略
    }
        access_log logs/brian.log main gzip buffer=128k flush=5s; 
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 }

 3、访问日志权限设置:

  设置权限主要也是为了安全做些优化(日志目录/opt/nginx/logs)

[root@Nginx nginx]# chown -R root.root /opt/nginx/logs
[root@Nginx nginx]# chmod -R 700 /opt/nginx/logs

  

 

posted @ 2018-03-26 16:12  Brian_Zhu  阅读(767)  评论(0编辑  收藏  举报