欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

如何关闭 禁止 Nginx 的访问日志和错误日志的输出 access.log error.log 有大用 有大大用 有大大大用

关闭 Nginx 的访问日志,可以有下面两种定义方式

  1. 把访问日志路径配置为 /dev/null/dev/null 是一个黑洞,所有往这里输入的信息都会被吞噬,找不回来的。

access_log /dev/null;#在原来的 log_format 的下一行 添加 access_log /dev/null;
  1. 直接把访问日志关闭 off

access_log off;  #在原来的 log_format 的下一行 添加 access_log off;

那么这两个哪种好呢? 从性能的角度上看, access_log off; 是比较好的,省去了日志的写入操作

那么,你可能会问,error_log 是否也可以有这两种方式呢?

答案是错的,不想要 Nginx 的错误日志,只有一种办法

error_log /dev/null;     # 把原来的 error_log  logs/error.log  notice; 替换成 error_log /dev/null;

如果你写成了

error_log off;

那么就会在 nginx.conf 这个目录生成一个 off 文件,用于存放错误日志,不信你自己可以看看


来自  https://www.twle.cn/t/19362



nginx关闭日志


主要配置参数

#关闭或打印到指定目录
access_log off;
error_log  /dev/null;

nginx.conf

http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  /home/log/nginx/error.log  main;
    #access_log /home/log/nginx/access.log;
    access_log off;
    error_log  /home/log/nginx/logs/error.log;
    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;
        
        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
   
}


            来自   https://blog.csdn.net/BlizzardWu/article/details/120564157

  

普通分类: