我在AWS EC2中使用Nginx。 而且,我编写了日志access.log文件,并将其发送到AWS cloudWatch日志。
下面,在我的nginx和logrotate代码中。
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
server_names_hash_bucket_size 256;
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 /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name http://www.example.com;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location /alb-health-check {
access_log off;
}
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:9000/;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
keepalive_timeout 60;
}
}
}
/var/log/nginx/*log {
create 0644 nginx nginx
daily
rotate 30
missingok
notifempty
dateformat .%Y-%m-%d.log
maxage 90
mail myemail@example.com
errors myemail@example.com
compress
sharedscripts
postrotate
/bin/kill -USR1 `cat /run/nginx.pid 2>/dev/null` 2>/dev/null || true
endscript
}
根据上述设置正确记录了nginx日志,但是记录突然停止。
对ec2的访问和access.log为空。
我可以看到压缩的访问日志文件,并且不再记录该日志。
我是否必须重新运行每个“ sudo服务nginx重新加载”命令?
谢谢!