Nginx from entry to abandon (c)

Today to learn nginx log management, log and cut through the log script and save it.

nginx log management

In the log format is provided nginx

 http {
    log_format main  '$remote_addr - $remote_user [$time_local] "$request" '
                           '$status $body_bytes_sent "$http_referer" '
                           '"$http_user_agent" "$http_x_forwarded_for"';
    access_log /var/log/nginx/access.log main;
    }
 

Custom Service Logs

 server {
    listen 80;
    server_name z.com;
    access_log /var/log/nginx/z.com.access.log main;
 }

nginx cutting timing of the task is completed log

The principle: by writing a script that will copy the current log file out of time and name, then use regular scheduled task execution timing can be.

 # runlog.sh
 
 #!/bin/bash
 LOGPATH=/usr/local/nginx/logs/z.com.access.log
 BASEPATH=/data/$(date -d yesterday +%Y%m%d-%H%M%S)_zcom_access.log
 
 mv $LOGPATH $BASEPATH
 touch $LOGPATH
 
 /usr/local/nginx/sbin/nginx -s reopen $LOGPATH
 

 

Guess you like

Origin www.cnblogs.com/welisit/p/11020138.html