一、切割日志
1、創(chuàng)建腳本/usr/local/nginx/sbin/cut_nginx_log.sh,輸入以下內(nèi)容:
#!/bin/bash
# This script run at 00:00
# The Nginx logs path
logs_path="/usr/local/nginx/logs/"
mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
mv ${logs_path}access.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/access_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 `cat /usr/local/nginx/logs/nginx.pid`
2、設(shè)置crontab,每天凌晨00:00切割nginx訪問日志
crontab -e
輸入以下內(nèi)容:
00 00 * * * /bin/bash /usr/local/nginx/sbin/cut_nginx_log.sh
二、狀態(tài)監(jiān)測(cè)
需要在Nginx 安裝的時(shí)候添加如下子模塊:
./configure --prefix=/usr/local/nginx --with-http_stub_status_module
在nginx.conf根目錄下加入以下內(nèi)容,過程如下:
1.修改配置文件
vi /usr/local/nginx/conf/nginx.conf
#以下面加入以下內(nèi)容
location /NginxStatus {
stub_status on;
access_log on;
auth_basic "NginxStatus";
}
2.重啟nginx服務(wù)
$ nginx -s reload
3.測(cè)試
http://127.0.0.1/NginxStatus
Active connections: 1
server accepts handled requests
#nginx 總共處理了3個(gè)連接, 成功創(chuàng)建3 次握手, 總共處理了14個(gè)請(qǐng)求
3 3 14
Reading: 0 Writing: 1 Waiting: 0