Note _ Nginx log cutting and _ nginx log Cutting
Grep generates the nginx main configuration file
Egrep-v "# | ^ $" nginx. conf. default> nginx. conf
Log format
[Root @ vfast conf] # sed-n'21, 23 s/# // gp 'nginx. conf. default
Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request "'
'$ Status $ body_bytes_sent "$ http_referer "'
'"$ Http_user_agent" "$ http_x_forwarded_for "';
The specific configuration file is as follows:
[Root @ vfast conf] #Cat nginx. conf
Worker_processes 1;
Events {
Worker_connections 1024;
}
Http {
Include mime. types;
Default_type application/octet-stream;
Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request"' configure the log format
'$ Status $ body_bytes_sent "$ http_referer "'
'"$ Http_user_agent" "$ http_x_forwarded_for "';
Sendfile on;
Keepalive_timeout 65;
Server {
Listen 80;
Server_nameWww. blog. conf;
Location /{
RootHtml/www;
Index index.html index.htm;
}
Access_log logs/access_www.log main; Take www.blog.com as an example to generate related log files
Error_page 500 502 503 x.html;
Location =/50x.html {
Root html;
}
}
}
Create root directory
[Root @ vfast html] # mkdir www
[Root @ vfast www] # vim index.html
[Root @ vfast www] # cat index.html
Http://www.blog.com
Add hosts resolution
[Root @ vfast www] # vim/etc/hosts
[Root @ vfast www] # cat/etc/hosts
127.0.0.1 localhost. localdomain localhost4 localhost4.localdomain4
: 1 localhost. localdomain localhost6 localhost6.localdomain6
192.168.31.234 www.blog.com
Reload nginx
[Root @ vfast www] #/application/nginx/sbin/nginx-s reload
Test
[Root @ vfast www] # curl www.blog.com
Http://www.blog.com
Nginx generates all access logs to access_www.log by default, and performs log polling and cutting to facilitate log analysis and processing. The daily splitting method is used here.
The cut script is as follows:Cut_nginx_log.sh
#! /Bin/bash
Dateformat = 'date + % Y % m % d'
Basedir = "/application/nginx"
Nginxlogdir = "$ Basedir/logs"
Logname = "access_www"
[-D $ Nginxlogdir] & cd $ Nginxlogdir | exit 1
[-F $ {Logname}. log] | exit 1
/Bin/mv $ {Logname}. log $ {Logname }_$ {Dateformat}. Log
$ Basedir/sbin/nginx-s reload
Scheduled task execution: Execute cut_nginx_log.sh to cut logs at every day
00 00 ***/bin/sh/server/script/cut_nginx_logs.sh>/dev/null 2> & 1