一、切割日志
1、创建脚本/usr/local/nginx/sbin/cut_nginx_log.sh,输入以下内容:
#!/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、设置crontab,每天凌晨00:00切割nginx访问日志
crontab -e
输入以下内容:
00 00 * * * /bin/bash /usr/local/nginx/sbin/cut_nginx_log.sh
二、状态监测
需要在Nginx 安装的时候添加如下子模块:
./configure --prefix=/usr/local/nginx --with-http_stub_status_module
在nginx.conf根目录下加入以下内容,过程如下:
1.修改配置文件
vi /usr/local/nginx/conf/nginx.conf
#以下面加入以下内容
location /NginxStatus {
stub_status on;
access_log on;
auth_basic "NginxStatus";
}
2.重启nginx服务
$ nginx -s reload
3.测试
http://127.0.0.1/NginxStatus
Active connections: 1
server accepts handled requests
#nginx 总共处理了3个连接, 成功创建3 次握手, 总共处理了14个请求
3 3 14
Reading: 0 Writing: 1 Waiting: 0