国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

服務器之家:專注于服務器技術及軟件下載分享
分類導航

云服務器|WEB服務器|FTP服務器|郵件服務器|虛擬主機|服務器安全|DNS服務器|服務器知識|Nginx|IIS|Tomcat|

服務器之家 - 服務器技術 - Nginx - 詳解Nginx日志配置及日志切割

詳解Nginx日志配置及日志切割

2019-11-23 20:46losbyday Nginx

本篇文章主要介紹了詳解Nginx日志配置及日志切割,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

日志配置

日志對于統計排錯來說非常有利的。本文總結了nginx日志相關的配置如access_log、log_format、open_log_file_cache、log_not_found、log_subrequest、rewrite_log、error_log。

nginx有一個非常靈活的日志記錄模式。每個級別的配置可以有各自獨立的訪問日志。日志格式通過log_format命令來定義。

ngx_http_log_module是用來定義請求日志格式的。

1. access_log指令

語法:

?
1
2
3
4
access_log path [format [buffer=size [flush=time]]];
access_log path format gzip[=level] [buffer=size] [flush=time];
access_log syslog:server=address[,parameter=value] [format];
access_log off;

默認值: access_log logs/access.log combined;

配置段: http, server, location, if in location, limit_except

gzip壓縮等級。

buffer設置內存緩存區大小。

flush保存在緩存區中的最長時間。

不記錄日志:access_log off;

使用默認combined格式記錄日志:access_log logs/access.log 或 access_log logs/access.log combined;

2. log_format指令

語法: log_format name string …;

默認值: log_format combined “…”;

配置段: http

name表示格式名稱,string表示等義的格式。log_format有一個默認的無需設置的combined日志格式,相當于apache的combined日志格式,如下所示:

?
1
2
3
log_format combined '$remote_addr - $remote_user [$time_local] '
                  ' "$request" $status $body_bytes_sent '
                  ' "$http_referer" "$http_user_agent" ';

如果nginx位于負載均衡器,squid,nginx反向代理之后,web服務器無法直接獲取到客戶端真實的IP地址了。 $remote_addr獲取反向代理的IP地址。反向代理服務器在轉發請求的http頭信息中,可以增加X-Forwarded-For信息,用來記錄 客戶端IP地址和客戶端請求的服務器地址。

?
1
2
3
log_format porxy '$http_x_forwarded_for - $remote_user [$time_local] '
               ' "$request" $status $body_bytes_sent '
               ' "$http_referer" "$http_user_agent" ';

日志格式允許包含的變量注釋如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$remote_addr, $http_x_forwarded_for(反向) 記錄客戶端IP地址
$remote_user 記錄客戶端用戶名稱
$request 記錄請求的URL和HTTP協議
$status 記錄請求狀態
$body_bytes_sent 發送給客戶端的字節數,不包括響應頭的大小; 該變量與Apache模塊mod_log_config里的“%B”參數兼容。
$bytes_sent 發送給客戶端的總字節數。
$connection 連接的序列號。
$connection_requests 當前通過一個連接獲得的請求數量。
$msec 日志寫入時間。單位為秒,精度是毫秒。
$pipe 如果請求是通過HTTP流水線(pipelined)發送,pipe值為“p”,否則為“.”。
$http_referer 記錄從哪個頁面鏈接訪問過來的
$http_user_agent 記錄客戶端瀏覽器相關信息
$request_length 請求的長度(包括請求行,請求頭和請求正文)。
$request_time 請求處理時間,單位為秒,精度毫秒; 從讀入客戶端的第一個字節開始,直到把最后一個字符發送給客戶端后進行日志寫入為止。
$time_iso8601 ISO8601標準格式下的本地時間。
$time_local 通用日志格式下的本地時間。

[warning]發送給客戶端的響應頭擁有“sent_http_”前綴。 比如$sent_http_content_range。[/warning]

實例如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
http {
 log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                    '"$status" $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for" '
                    '"$gzip_ratio" $request_time $bytes_sent $request_length';
 
 log_format srcache_log '$remote_addr - $remote_user [$time_local] "$request" '
                '"$status" $body_bytes_sent $request_time $bytes_sent $request_length '
                '[$upstream_response_time] [$srcache_fetch_status] [$srcache_store_status] [$srcache_expire]';
 
 open_log_file_cache max=1000 inactive=60s;
 
 server {
 server_name ~^(www\.)?(.+)$;
 access_log logs/$2-access.log main;
 error_log logs/$2-error.log;
 
 location /srcache {
 access_log logs/access-srcache.log srcache_log;
 }
 }
}

3. open_log_file_cache指令

語法:

?
1
2
open_log_file_cache max=N [inactive=time] [min_uses=N] [valid=time];
open_log_file_cache off;

默認值: open_log_file_cache off;

配置段: http, server, location

對于每一條日志記錄,都將是先打開文件,再寫入日志,然后關閉。可以使用open_log_file_cache來設置日志文件緩存(默認是off),格式如下:

參數注釋如下:

  • max:設置緩存中的最大文件描述符數量,如果緩存被占滿,采用LRU算法將描述符關閉。
  • inactive:設置存活時間,默認是10s
  •  min_uses:設置在inactive時間段內,日志文件最少使用多少次后,該日志文件描述符記入緩存中,默認是1次
  • valid:設置檢查頻率,默認60s
  •  off:禁用緩存

 實例如下:

?
1
open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;

4. log_not_found指令

語法: log_not_found on | off;

默認值: log_not_found on;

配置段: http, server, location

是否在error_log中記錄不存在的錯誤。默認是。

5. log_subrequest指令

語法: log_subrequest on | off;

默認值: log_subrequest off;

配置段: http, server, location

是否在access_log中記錄子請求的訪問日志。默認不記錄。

6. rewrite_log指令

由ngx_http_rewrite_module模塊提供的。用來記錄重寫日志的。對于調試重寫規則建議開啟。 Nginx重寫規則指南

語法: rewrite_log on | off;

默認值: rewrite_log off;

配置段: http, server, location, if

啟用時將在error log中記錄notice級別的重寫日志。

7. error_log指令

語法: error_log file | stderr | syslog:server=address[,parameter=value] [debug | info | notice | warn | error | crit | alert | emerg];

默認值: error_log logs/error.log error;

配置段: main, http, server, location

配置錯誤日志。

--------------------------------------------------------------------------------

日志切割

nginx日志默認情況下統統寫入到一個文件中,文件會變的越來越大,非常不方便查看分析。以日期來作為日志的切割是比較好的,通常我們是以每日來做統計的。下面來說說nginx日志切割。

1. 定義日志輪滾策略

?
1
# vim nginx-log-rotate
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/data/weblogs/*.log {
  nocompress
  daily
  copytruncate
  create
  notifempty
  rotate 7
  olddir /data/weblogs/old_log
  missingok
  dateext
  postrotate
    /bin/kill -HUP `cat /var/run/nginx.pid 2> /dev/null` 2> /dev/null || true
  endscript
}

[warning]/data/weblogs/*.log使用通配符時,/data/weblogs/目錄下的所有匹配到的日志文件都將切割。如果要切割特定日志文件,就指定到該文件。[/warning]

2. 設置計劃任務

?
1
59 23 * * * root ( /usr/sbin/logrotate -f /PATH/TO/nginx-log-rotate)

這樣每天23點59分鐘執行日志切割。

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。

原文鏈接:http://www.cnblogs.com/losbyday/p/5839738.html

延伸 · 閱讀

精彩推薦
Weibo Article 1 Weibo Article 2 Weibo Article 3 Weibo Article 4 Weibo Article 5 Weibo Article 6 Weibo Article 7 Weibo Article 8 Weibo Article 9 Weibo Article 10 Weibo Article 11 Weibo Article 12 Weibo Article 13 Weibo Article 14 Weibo Article 15 Weibo Article 16 Weibo Article 17 Weibo Article 18 Weibo Article 19 Weibo Article 20 Weibo Article 21 Weibo Article 22 Weibo Article 23 Weibo Article 24 Weibo Article 25 Weibo Article 26 Weibo Article 27 Weibo Article 28 Weibo Article 29 Weibo Article 30 Weibo Article 31 Weibo Article 32 Weibo Article 33 Weibo Article 34 Weibo Article 35 Weibo Article 36 Weibo Article 37 Weibo Article 38 Weibo Article 39 Weibo Article 40
主站蜘蛛池模板: 91麻豆精品国产91久久久更新资源速度超快 | 亚洲精品久久久 | 中文在线一区二区三区 | 亚洲激情一区 | 亚洲欧美中文字幕 | 亚洲日韩中文字幕一区 | 精品久久国产老人久久综合 | 国产女爽爽视频精品免费 | 精品99在线 | 最近2019中文字幕大全视频10 | 国产在线资源 | 一区免费视频 | 成人网址在线观看 | 一区二区三区免费观看视频 | 激情欧美一区二区免费视频 | 91久久国产综合久久 | 亚洲经典一区 | 黄色网址在线免费 | 精品久久国产字幕高潮 | 成人一区二区在线观看 | 自拍偷拍 欧美日韩 | 性做久久久久久久久 | 阿v视频在线观看 | 亚洲国产aⅴ成人精品无吗 久久综合久久久 | 亚洲日韩中文字幕一区 | 波多野结衣先锋影音 | 精品福利在线 | 国产成人精品av | 久久久久久一区 | 亚洲国产精品99久久久久久久久 | 伊人逼逼| 欧美视频一区 | 亚洲一区在线日韩在线深爱 | 日韩成人在线一区二区 | 欧美日本韩国一区二区 | 免费级毛片 | 精品女同一区二区三区在线绯色 | 中文字幕国产视频 | 成人爽a毛片一区二区免费 久久久久亚洲精品 | 久久久久久麻豆 | 日韩免费在线观看视频 |