日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

Nginx的error_log和Access_log分析 nginx access log( 二 )


ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
ngx_http_core_loc_conf_t *prev = parent;
ngx_http_core_loc_conf_t *conf = child;
。。。。。。
if (conf->error_log == NULL) {
if (prev->error_log) {
conf->error_log = prev->error_log;
} else {
conf->error_log = &cf->cycle->new_log;
}
}
。。。。。。
}
那為什么不把兩個指令合并到一起呢 。
首先看一下模塊注冊順序:
ngx_module_t *ngx_modules[] = {
&ngx_core_module,
&ngx_errlog_module,
&ngx_conf_module,
&ngx_events_module,
&ngx_event_core_module,
&ngx_rtsig_module,
&ngx_epoll_module,
&ngx_regex_module,
&ngx_http_module,
&ngx_http_core_module,
&ngx_http_log_module,
......
}
可見ngx_errlog_module 和 ngx_http_core_module中間有n多模塊 。這些模塊是獨立于http的,而且需要日志的打印,這些日志肯定是需要記錄的 。
則此模塊不可省,那么考慮把ngx_http_core_module的error_log合并過來呢,想想也不行,為什么呢?
想想ngx_errlog_module將error_log信息存在哪里,想想ngx_http_core_module的error_log信息存在哪里 。
在調(diào)用ngx_error_log時候,把針對不同server或者location的error_log信息存儲在哪里 。(模塊之間不能深度耦合)
為了兩個模塊互不影響,這是個好辦法呀!
二:access_log
接下來看一下access_log,access_log指令是屬于ngx_http_log_module模塊 。
ngx_http_log_module有三個指令:
static ngx_command_t ngx_http_log_commands[] = {
{ ngx_string("log_format"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_2MORE,
ngx_http_log_set_format,
NGX_HTTP_MAIN_CONF_OFFSET,
0,
NULL },
{ ngx_string("access_log"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|NGX_HTTP_LMT_CONF|NGX_CONF_TAKE123,
ngx_http_log_set_log,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL },
{ ngx_string("open_log_file_cache"),
NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1234,
ngx_http_log_open_file_cache,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL },
ngx_null_command
};
每個block都可以配置上面的指令 ,這些指令對應(yīng)著各個block配置中的loc[ngx_http_log_module.index](要理解這個,需要知道配置文件的整個解析過程和block對應(yīng)關(guān)系),即下面這個數(shù)據(jù)結(jié)構(gòu):
typedef struct {
ngx_array_t *logs; /* array of ngx_http_log_t */
ngx_open_file_cache_t *open_file_cache;
time_t open_file_cache_valid;
ngx_uint_t open_file_cache_min_uses;
ngx_uint_t off; /* unsigned off:1 */
} ngx_http_log_loc_conf_t;
關(guān)于access_log主要有以下幾個點:
1、ngx_http_log_module是屬于nginx狀態(tài)機(jī)最后一個階段NGX_HTTP_LOG_PHASE的處理模塊,即一個http請求結(jié)束時執(zhí)行的,它的任務(wù)就是打印這次request的訪問情況 。
2、access_log支持根據(jù)變量指令路徑,如:
access_log logs/'$remote_addr'access.log main;
3、不管是變量路徑還是常量路徑,都將信息放入了 ngx_http_log_loc_conf_t的logs這個數(shù)組里進(jìn)行管理,logs數(shù)組的元素是ngx_http_log_t 。
typedef struct {
ngx_open_file_t *file;
ngx_http_log_script_t *script;
time_t disk_full_time;
time_t error_log_time;
ngx_http_log_fmt_t *format;
} ngx_http_log_t;
當(dāng)是常量的時候使用file記錄,這個文件記錄會放入到cycle->open_files
struct ngx_open_file_s {
ngx_fd_t fd;
ngx_str_t name;
u_char *buffer;
u_char *pos;
u_char *last;
};
當(dāng)是變量的時候使用script記錄

推薦閱讀