Nginx 切割日志 + 狀態(tài)監(jiān)測(cè)

一、切割日志

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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容