一.nginx配置文件的基本结构
....
events
{
....
}
http
{
....
server
{
.....
}
server
{
....
}
}
虚拟主机的配置
http
{
server
{
listen 80;
server_name _*;
access_log /logs/default.access.log;
location /{
index index.html
root /data0/docs/docs
}
}
}
二.日志
1.关于日志的指令
关于日志的两条指令,log_format(指定日志的格式)和access_log(日志存放的路径)
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 logs/access.log main;
host.access.log中按照log_format格式记录的日志
192.168.41.100 - - [24/May/2017:22:06:55 +0800] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36" "-"
2.日志文件的切割
通过信号量USER1重新生成新的日志
mv ../logs/access_log 20170524.log //先将原来的日志备份
kill -USR1 'cat /logs/nginx.pid' //让nginx重新生成一个新的文件
3.定时切割日志的脚本
kill -HUP nginx master pid == kill -HUP `cat nginx.pid`
这里的引号为单反引号