Nginx – access_log格式及配置

來源:互聯網
上載者:User

標籤:cron   add   day   格式   div   緩衝   儲存   arp   定義   

日誌格式

日誌內容

192.168.199.164 – jeson [14/Apr/2018:07:17:09 +0800] “GET /?feed=rss2 HTTP/1.1” 200 13883 “http://knowledge.me/” “Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko” “-“

日誌變數

‘$remote_addr  – $remote_user [$time_local] “$request” ‘
‘$status $body_bytes_sent “$http_referer” ‘
‘“$http_user_agent” “$http_x_forwarded_for”‘;

 

日誌配置

 

一般情況下,訪問日誌基於虛擬機器主機(server標籤段)內,以便於針對該網站的訪問記錄。

 

文法:access_log path [format [buffer=size] [gzip[=level]] [flush=time] [if=condition]];

 

樣本:

 

access_log off; #關閉日誌功能
access_log /spool/logs/nginx-access.log main gzip buffer=32k fush=5s; #日誌儲存在路徑下,使用main定義的格式,用壓縮及緩衝32k後,5秒後刷入磁碟。

 

思考的問題

 

當大並發量的時候,記錄檔會對磁碟的IO有壓力。需要使用 buffer=size gzip[=level] flush=time 進行最佳化。

 

 

日誌的輪詢

 

nginx的日誌沒有自動輪詢的功能,也就是記錄檔不會按年月日來組建檔案。

cat /usr/local/nginx/logs/cut_longhsuai.sh#!/bin/bash# cut the access log for www.longshuai.combasedir=/usr/local/nginxold_log_path=$basedir/logs/access.loglog_save_path=$basedir/logssave_log_name=access_$(date -d “yesterday” +”%Y%m%d”).log[ -f “$old_log_path” ] || exit 1/bin/mv $old_log_path $log_save_path/$save_log_name$basedir/sbin/nginx -s reopen
添加到定時任務計劃
chmod +x /usr/local/nginx/logs/cut_longshuai.shcrontab -e00 00 * * * /bin/sh /usr/local/nginx/logs/cut_longshuai.sh &>/dev/null

 

 

 

 

Nginx – access_log格式及配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.