Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx service optimization (4) Log segmentation

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Log cutting of Nginx

As the Nginx elapsed time, so did the logs. In order to grasp the running status of Nginx, we need to pay attention to Nginx log files all the time. Too large log files are a disaster for monitoring, so we need to cut log files regularly.

Nginx itself does not have the function of log segmentation, but the automatic log cutting can be realized through the script of Nginx signal control function, and the log can be cut periodically through the planned task of Linux.

1. Under the "/ usr/local/nginx" directory Add a log segmentation script [root@localhost nginx] # vim fenge.sh / / script #! / bin/bash#Filename:fenge.shd=$ (date-d "- 1 day"+% Y%m%d") logs_path= "/ var/log/nginx" pid_path= "/ usr/local/nginx/logs/nginx.pid" [- d $logs_path] | | mkdir-p $logs_pathmv / usr/local/nginx/logs/access.log ${logs_path} / test.com-access.log-$dkill-USR1 $(cat $pid_path) find $logs_path-mtime + 30 | xargs rm-rf [root@localhost nginx] # chmod + x fenge.sh / / add execution permission [root@localhost nginx] # lsclient_body_temp conf fastcgi_temp fenge.sh html logs proxy_temp sbin scgi_temp uwsgi_ temp [root @ localhost nginx] # 2. This directory is not available before execution of script [root@localhost nginx] # ls / var/log/nginx / / ls: unable to access / var/log/nginx: no file or directory [root@localhost nginx] # / fenge.sh / / execute script [root@localhost nginx] # ls / var/log/nginx / / directory created successfully, and generate log file test.com-access.log-20191112 [root@localhost nginx] #

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report