Nginx logs are segmented by day. because nginx logs only support partitioning by server_name or size, it is unacceptable for me to get used to apache logs by website every day, so I found several ways to split nginx by day on the internet and found that they are all mutual...
Nginx logs are segmented by day. because nginx logs only support partitioning by server_name or size, it is unacceptable for me to get used to apache logs by website every day, so I found several ways to split nginx by day on the internet and found that they all copied each other. in particular, there was a command in it: kill-9 'cat nginx. pid '. I think it is unreliable to kill the nginx sub-process. Www.2cto.com I suddenly thought of the method of separating rsyslog logs when I used to develop openstack cloud storage. The principle of ease of use is:
1. copy rotatelogs from the apache bin directory on an apache-installed machine to mkdir-p/opt/nginx_logs cp rotatelogs/opt/nginx_logs/chmod under/opt/nginx_logs/+ x/opt/nginx_logs/rotatelogs 2. create a famous pipe www.2cto.com mkdir/opt/nginx_logs/abc_www/mkfifo/opt/nginx_logs/abc_www/access_log 3. add access_log/opt/nginx_logs/abc_www/access_log to the nginx configuration file server; 4. create the log directory mkdir/opt/nginx_logs/abc_www/log/5. create a log segmentation script to prevent rotatelogs from being killed. [root @ localhost nginx_logs] # cat/opt/nginx_logs/abc_www/rotate. sh baselogdir =/opt/nginx_logs/abc_www rotatelogs =/opt/nginx_logs/rotatelogs while [1] do echo 'date + "% F % T" '"rotatelogs access start" $ rotatelogs $ baselogdir/log/access _ % Y % m % d. log 86400 480 <$ baselogdir/access_log echo 'date + "% F % T" '"rotatelogs access stop" sleep 1; done www.2cto.com 6. create the startup log segmentation script [root @ localhost nginx_logs] # cat/opt/nginx_logs/abc_www/run. sh/opt/nginx_logs/abc_www/rotate. sh>/opt/nginx_logs/abc_www/log/access-rotate.log 2> & 1 & 7. final effect
End
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service