nginx日誌打印linux
http屬性log_format來設置日誌格式 ,參考 https://www.jb51.net/article/52573.htm 《nginx日誌配置指令詳解》 nginx
log_format myformat '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' ' "$http_user_agent" "$http_x_forwarded_for「 ’; //定義一個以myformat命名的日誌格式,通常來講保持默認格式足矣瀏覽器
$remote_addr 遠程地址.net
$remote_user 若是用戶登陸,那麼記錄用戶名日誌
$time_local 本地時間orm
$request 記錄請求的URL和HTTP協議server
$status 記錄請求狀態htm
$body_bytes_sent nginx返回給客戶端的響應體的字節數(即不含響應頭)。進程
$http_referer 記錄從哪一個頁面連接訪問過來的rem
$http_user_agent 使用的瀏覽器
access_log logs/my.log myformat //access_log屬性能夠存在於任何一個地方:server http。第二個參數是定義日誌存放在哪一個位置,第三個參數是日誌使用什麼格式。
nginx日誌切割:linux中能夠使用Crontab定時任務,定時切割日誌文件,命令:mv access.log access.log.20181106kill -USR1 Nginx 主進程號 // 讓nginx從新生成一個日誌文件access.log