我昨天开启了nginx日志功能,并也看到了生成的日志。但我今天凌晨的时候发现昨天的日志内容没有了。我也并没有在log目录中看任何诸如access.log.2018.02.12这样类似格式的文件。这让我很担心,不知道是配置方面的问题,还是被黑客攻击了。把我日志清除了。我nginx开启日志的配置如下:
user root;
worker_processes 4;
#error_log /dev/null;
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid conf/nginx.pid;
worker_rlimit_nofile 1024;
events {
use epoll;
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
include proxy.conf;
log_format yundns_log '$server_name $remote_addr [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"';
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 logs/access.log main;
server_tokens off;
sendfile on;
tcp_nopush on;
server_names_hash_bucket_size 256;
client_header_buffer_size 256k;
#large_client_header_buffers 4 32k;
large_client_header_buffers 4 256k;
client_body_buffer_size 256k;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
client_max_body_size 50m;
keepalive_timeout 120;
fastcgi_intercept_errors on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
#fastcgi_buffer_size 64k;
#fastcgi_buffers 8 64k;
#fastcgi_busy_buffers_size 128k;
#fastcgi_temp_file_write_size 128k;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
server {
listen 80;
server_name image.coolcarstime.com image1.coolcarstime.com;
#access_log off;
.....................................................................................................
我推荐你使用这个脚本,这个可以按天保存Nginx日志,你可以根据你的情况自行修改,最好保存日志的地方不是在同一个地方
#!/bin/bash
declare logs_path="/var/log/nginx";
declare need_delete_path=${logs_path}/$(date -d "7 days ago" "+%Y_%m_%d");
declare yestoday_log_path=${logs_path}/$(date -d "yesterday" "+%Y_%m_%d");
rm -rf ${need_delete_path}
rm -rf ${yestoday_log_path}
mv ${logs_path}/today ${yestoday_log_path}
mkdir -p ${logs_path}/today
/etc/init.d/nginx reload
尝试添加一下代码
access_log path [format [buffer=size] [gzip[=level]] [flush=time] [if=condition]];
path修改成你自己的日志路径