Ubuntu

Ubuntu 上 nginx 的名為“etc/nginx/on”的大文件

  • January 5, 2022

當我在 Ubuntu 環境下進行開發時,我收到了伺服器即將耗盡儲存空間的警報。所以我追踪了哪個文件在磁碟上佔用了這麼多空間。我能夠發現有一個名為on. etc/nginx(我正在使用 nginx )

這個文件有什麼作用?這個文件佔用了7.7G,它的類型是ASCII文本,行很長(我用file *命令算出來的)

我想通過刪除這個文件來管理伺服器的儲存。這樣做安全嗎?我不能只是不斷增加伺服器的儲存空間。

如果任何事情看起來可疑和錯誤,任何建議和建議將不勝感激。

先感謝您。

這是 nginx.conf

user www-data;
worker_processes auto;


error_log  /var/log/nginx/error.log crit;
pid        /var/run/nginx.pid;


events {
   worker_connections  4000;
   use epoll;
   multi_accept on;
}


http {
   # cache informations about FDs, frequently accessed files
   # can boost performance, but you need to test those values
   open_file_cache max=200000 inactive=20s;
   open_file_cache_valid 30s;
   open_file_cache_min_uses 2;
   open_file_cache_errors on;

   # to boost IO on HDD we can disable access logs
   access_log on;
   access_log  /var/log/nginx/access.log;

   sendfile on;
   tcp_nopush on;
   tcp_nodelay on;
   types_hash_max_size 2048;
   server_tokens off;

   include       /etc/nginx/mime.types;
   default_type  application/octet-stream;

   gzip on;
   gzip_min_length 10240;
   gzip_proxied expired no-cache no-store private auth;
   #gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/json application/xml;
   gzip_types text/plain text/css application/javascript text/xml application/xml+rss;
   gzip_disable "MSIE [1-6]\.";
   gzip_vary on;

   client_body_buffer_size 10K;
   client_header_buffer_size 1k;
   client_max_body_size 20m;
   large_client_header_buffers 2 1k;

   fastcgi_buffers 8 16k;
   fastcgi_buffer_size 32k;
   fastcgi_connect_timeout 300;
   fastcgi_send_timeout 300;
   fastcgi_read_timeout 300;

   # limit the number of connections per single IP
   limit_conn_zone $binary_remote_addr zone=conn_limit_per_ip:10m;

   # limit the number of requests for a given session
   limit_req_zone $binary_remote_addr zone=req_limit_per_ip:10m rate=5r/s;

   # zone which we want to limit by upper values, we want limit whole server
   server {
           limit_conn conn_limit_per_ip 10;
           limit_req zone=req_limit_per_ip burst=10 nodelay;

           # Expire rules for static content

           # cache.appcache, your document html and data
           location ~* \.(?:manifest|appcache|html?|xml|json)$ {
                   expires -1;
                   # access_log logs/static.log; # I don't usually include a static log
           }

           # Feed
           location ~* \.(?:rss|atom)$ {
                   expires 1h;
                   add_header Cache-Control "public";
           }

           # Media: images, icons, video, audio, HTC
           location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
                   expires 1M;
                   access_log off;
                   add_header Cache-Control "public";
           }

           # CSS and Javascript
           location ~* \.(?:css|js)$ {
                   expires 1y;
                   access_log off;
                   add_header Cache-Control "public";
           }

   }

   # server will close connection after this time -- default 75
   keepalive_timeout 30;

   # number of requests client can make over keep-alive -- for testing environment
   keepalive_requests 100000;

   ##
   # Virtual Host Configs
   ##

   include /etc/nginx/conf.d/*.conf;
   include /etc/nginx/sites-enabled/*;
}

檢查儲存

/etc/nginx# ls -alSh
total 7.7G
-rw-r--r--   1 www-data root 7.7G Sep 20 00:36 on
drwxr-xr-x 126 root     root  12K Sep 15 16:15 ..
drwxr-xr-x   5 root     root 4.0K Jul  6 13:44 .
drwxr-xr-x   2 root     root 4.0K May 26 02:13 conf.d
drwxr-xr-x   2 root     root 4.0K Jul  6 13:42 sites-enabled
drwxr-xr-x   4 root     root 4.0K Nov 15  2016 ssl
-rw-r--r--   1 root     root 3.9K Apr 26 01:48 mime.types
-rw-r--r--   1 root     root 3.6K Sep 13  2016 win-utf
-rw-r--r--   1 root     root 3.5K Nov 19  2016 docker_default
-rw-r--r--   1 root     root 2.8K Jul  6 13:44 nginx.conf
-rw-r--r--   1 root     root 2.8K Sep 13  2016 koi-utf
-rw-r--r--   1 root     root 2.2K Sep 13  2016 koi-win
-rw-r--r--   1 root     root 1007 Sep 13  2016 fastcgi_params
-rw-r--r--   1 root     root  664 Sep 13  2016 uwsgi_params
-rw-r--r--   1 root     root  636 Sep 13  2016 scgi_params
-rw-r--r--   1 root     root  417 Dec  1  2016 Dockerfile
lrwxrwxrwx   1 root     root   22 Sep 13  2016 modules -> /usr/lib/nginx/modules

找出它是什麼類型

/etc/nginx# file *
conf.d:         directory 
docker_default: ASCII text, with very long lines
Dockerfile:     UTF-8 Unicode text
fastcgi_params: ASCII text
koi-utf:        C source, ASCII text
koi-win:        C source, ASCII text
mime.types:     ASCII text
modules:        symbolic link to `/usr/lib/nginx/modules' 
nginx.conf:     ASCII text
on:             ASCII text, with very long lines
scgi_params:    ASCII text
sites-enabled:  directory 
ssl:            directory 
uwsgi_params:   ASCII text
win-utf:        C source, ASCII text

據我所知,但我可能錯了,不存在這樣的指令:access_log on;

我懷疑這個指令使 NGinx 寫入訪問日誌文件on而不是您使用指定的文件access_log /var/log/nginx/access.log;

可以使用access_log off;現有指令禁用訪問日誌。

要保留訪問日誌刪除access_log on;,它會將日誌寫入access_log指令中指定的文件:access_log /var/log/nginx/access.log;

回答:是的,刪除這個文件是安全的(或者備份它 - 將它移到別處 - 如果你想跟踪這些訪問日誌)。

引用自:https://serverfault.com/questions/874552