亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb

首頁 > 網站 > Nginx > 正文

全面了解Nginx中的HTTP協議相關模塊配置

2024-08-30 12:21:52
字體:
來源:轉載
供稿:網友
HTTP的處理是Nginx服務器的最重要功能,這里我們就帶大家來全面了解Nginx中的HTTP協議相關模塊配置,需要的朋友可以參考下

要理解 HTTP 模塊配置解析的過程,首先需要對 nginx 的配置文件結構做一個了解

nginx 的配置文件是用樹狀結構組織的,每個 NGX_CORE_MODULE 作為根統領著其下的所有配置項

而如下圖所示,HTTP 模塊的配置被分成了 main、server、location 三層

2016713180141450.png (901×409)

整個 nginx 配置解析的過程其實就是這棵樹的深度遍歷過程

而遍歷 HTTP 子樹的函數就是下面要介紹的 ngx_http_block

配置文件解析 -- http 配置塊
當我們需要使用 http 模塊的時候,我們需要在配置文件中加入 http 配置塊:

http { // http 配置塊 {{{  include    mime.types;  default_type application/octet-stream;  #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;  sendfile    on;  #tcp_nopush   on;  #keepalive_timeout 0;  keepalive_timeout 65;  #gzip on;  server {    listen    8001;    server_name localhost;    #autoindex  on;    #charset koi8-r;    #access_log logs/host.access.log main;    location / {      root  /var/www/;      index index.html index.htm index.php;

在 http 配置塊中,我們配置了 http 連接相關的信息,HTTP 框架也正是從這里啟動的.

在 nginx 初始化的過程中,執行了 ngx_init_cycle 函數,其中進行了配置文件解析,調用了 ngx_conf_parse 函數

配置文件解析

函數 ngx_conf_handler 根據配置項的 command 調用了對應的 set 回調函數

// static ngx_int_t ngx_conf_handler(ngx_conf_t *cf, ngx_int_t last)// 配置項解析 {{{static ngx_int_tngx_conf_handler(ngx_conf_t *cf, ngx_int_t last){  char      *rv;  void      *conf, **confp;  ngx_uint_t   i, found;  ngx_str_t   *name;  ngx_command_t *cmd;  name = cf->args->elts;  found = 0;  for (i = 0; ngx_modules[i]; i++) {    cmd = ngx_modules[i]->commands;    if (cmd == NULL) {      continue;    }    for ( /* void */ ; cmd->name.len; cmd++) {      if (name->len != cmd->name.len) {        continue;      }      if (ngx_strcmp(name->data, cmd->name.data) != 0) {        continue;      }

閱讀各模塊的 ngx_command_t 命令配置結構,可以找到:

// static ngx_command_t ngx_http_commands// http 模塊命令結構 {{{static ngx_command_t ngx_http_commands[] = {  { ngx_string("http"),   NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,   ngx_http_block,   0,   0,   NULL },   ngx_null_command}; // }}}

http 配置塊解析 -- ngx_http_block

2016713180305891.jpg (391×1645)

在解析到 http 配置塊時,執行了對應的 set 回調函數 ngx_http_block

static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf){  char            *rv;  ngx_uint_t          mi, m, s;  ngx_conf_t          pcf;  ngx_http_module_t      *module;  ngx_http_conf_ctx_t     *ctx;  ngx_http_core_loc_conf_t  *clcf;  ngx_http_core_srv_conf_t  **cscfp;  ngx_http_core_main_conf_t  *cmcf;  /* the main http context */  ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));  if (ctx == NULL) {    return NGX_CONF_ERROR;  } // 創建 http 配置結構,保存所有 http 模塊的配置信息  *(ngx_http_conf_ctx_t **) conf = ctx;  /* count the number of the http modules and set up their indices */  ngx_http_max_module = 0;  for (m = 0; ngx_modules[m]; m++) {    if (ngx_modules[m]->type != NGX_HTTP_MODULE) {      continue;    } // 重新設定 HTTP 模塊序號    ngx_modules[m]->ctx_index = ngx_http_max_module++;  }  /* the http main_conf context, it is the same in the all http contexts */  ctx->main_conf = ngx_pcalloc(cf->pool,                 sizeof(void *) * ngx_http_max_module);  if (ctx->main_conf == NULL) {    return NGX_CONF_ERROR;  }  /*   * the http null srv_conf context, it is used to merge   * the server{}s' srv_conf's   */  ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);  if (ctx->srv_conf == NULL) {    return NGX_CONF_ERROR;  }  /*   * the http null loc_conf context, it is used to merge   * the server{}s' loc_conf's   */  ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);  if (ctx->loc_conf == NULL) {    return NGX_CONF_ERROR;  }  /*   * create the main_conf's, the null srv_conf's, and the null loc_conf's   * of the all http modules   */  for (m = 0; ngx_modules[m]; m++) {    if (ngx_modules[m]->type != NGX_HTTP_MODULE) {      continue;    }    module = ngx_modules[m]->ctx;    mi = ngx_modules[m]->ctx_index;    if (module->create_main_conf) {  // 調用每個模塊的 create_main_conf 回調函數  // 創建自己的 main_conf  //  // ngx_http_core_module  ngx_http_core_create_main_conf  // ngx_http_log_module  ngx_http_log_create_main_conf  // ngx_http_upstream_module  ngx_http_upstream_create_main_conf  // ngx_http_map_module  ngx_http_map_create_conf  // ngx_http_ssi_filter_module ngx_http_ssi_create_main_conf  // ngx_http_charset_filter_module ngx_http_charset_create_main_conf      ctx->main_conf[mi] = module->create_main_conf(cf);      if (ctx->main_conf[mi] == NULL) {        return NGX_CONF_ERROR;      }    }    if (module->create_srv_conf) {  // 調用每個模塊的 create_srv_conf 回調函數  // 創建自己的 srv_conf  //  // ngx_http_core_module   ngx_http_core_create_srv_conf  // ngx_http_ssl_module   ngx_http_ssl_create_srv_conf  // ngx_http_upstream_hash_module ngx_http_upstream_hash_create_conf  // ngx_http_upstream_least_conn_module ngx_http_upstream_least_conn_create_conf  // ngx_http_upstream_keepalive_module ngx_http_upstream_keepalive_create_conf      ctx->srv_conf[mi] = module->create_srv_conf(cf);      if (ctx->srv_conf[mi] == NULL) {        return NGX_CONF_ERROR;      }    }    if (module->create_loc_conf) {  // 調用每個模塊的 create_loc_conf 回調函數  // 創建自己的 loc_conf  //  // ngx_http_core_module  ngx_http_core_create_loc_conf  // ngx_http_log_module  ngx_http_log_create_loc_conf  // ngx_http_gzip_static_module ngx_http_gzip_static_create_conf  // ngx_http_autoindex_module ngx_http_autoindex_create_loc_conf  // ngx_http_index_module  ngx_http_index_create_loc_conf  // ngx_http_auth_basic_module ngx_http_auth_basic_create_loc_conf  // ngx_http_access_module  ngx_http_access_create_loc_conf  // ngx_http_limit_conn_module ngx_http_limit_conn_create_conf  // ngx_http_limit_req_module ngx_http_limit_req_create_conf  // ngx_http_referer_module  ngx_http_referer_create_conf  // ngx_http_rewrite_module  ngx_http_rewrite_create_loc_conf  // ngx_http_proxy_module  ngx_http_proxy_create_loc_conf  // ngx_http_fastcgi_module  ngx_http_fastcgi_create_loc_conf  // ngx_http_uwsgi_module  ngx_http_uwsgi_create_loc_conf  // ngx_http_scgi_module  ngx_http_scgi_create_loc_conf  // ngx_http_memcached_module ngx_http_memcached_create_loc_conf  // ngx_http_browser_module  ngx_http_browser_create_conf  // ngx_http_gzip_filter_module ngx_http_gzip_create_conf  // ngx_http_ssi_filter_module ngx_http_ssi_create_loc_conf  // ngx_http_charset_filter_module ngx_http_charset_create_loc_conf  // ngx_http_userid_filter_module ngx_http_userid_create_conf  // ngx_http_headers_filter_module ngx_http_headers_create_conf  // ngx_http_copy_filter_module ngx_http_copy_filter_create_conf      ctx->loc_conf[mi] = module->create_loc_conf(cf);      if (ctx->loc_conf[mi] == NULL) {        return NGX_CONF_ERROR;      }    }  }  pcf = *cf;  cf->ctx = ctx;  for (m = 0; ngx_modules[m]; m++) {    if (ngx_modules[m]->type != NGX_HTTP_MODULE) {      continue;    }    module = ngx_modules[m]->ctx;    if (module->preconfiguration) {  // 調用每個模塊的 preconfiguration 回調函數  //  // ngx_http_core_module  ngx_http_core_preconfiguration  // ngx_http_upstream_module  ngx_http_upstream_add_variables  // ngx_http_ssl_module  ngx_http_ssl_add_variables  // ngx_http_proxy_module  ngx_http_proxy_add_variables  // ngx_http_fastcgi_module  ngx_http_fastcgi_add_variables  // ngx_http_browser_module  ngx_http_browser_add_variable  // ngx_http_stub_status_module ngx_http_stub_status_add_variables  // ngx_http_gzip_filter_module ngx_http_gzip_add_variables  // ngx_http_ssi_filter_module ngx_http_ssi_preconfiguration  // ngx_http_userid_filter_module ngx_http_userid_add_variables      if (module->preconfiguration(cf) != NGX_OK) {        return NGX_CONF_ERROR;      }    }  }  /* parse inside the http{} block */  cf->module_type = NGX_HTTP_MODULE;  cf->cmd_type = NGX_HTTP_MAIN_CONF;  rv = ngx_conf_parse(cf, NULL);  if (rv != NGX_CONF_OK) {    goto failed;  }  /*   * init http{} main_conf's, merge the server{}s' srv_conf's   * and its location{}s' loc_conf's   */  cmcf = ctx->main_conf[ngx_http_core_module.ctx_index];  cscfp = cmcf->servers.elts;  for (m = 0; ngx_modules[m]; m++) {    if (ngx_modules[m]->type != NGX_HTTP_MODULE) {      continue;    }    module = ngx_modules[m]->ctx;    mi = ngx_modules[m]->ctx_index;    /* init http{} main_conf's */    if (module->init_main_conf) {  // 調用每個模塊的 init_main_conf 回調函數  // 初始化自己的 main_conf  //  // ngx_http_core_module  ngx_http_core_init_main_conf  // ngx_http_upstream_module ngx_http_upstream_init_main_conf  // ngx_http_ssi_filter_module ngx_http_ssi_init_main_conf      rv = module->init_main_conf(cf, ctx->main_conf[mi]);      if (rv != NGX_CONF_OK) {        goto failed;      }    } // 合并同名配置項    rv = ngx_http_merge_servers(cf, cmcf, module, mi);    if (rv != NGX_CONF_OK) {      goto failed;    }  }  /* create location trees */  for (s = 0; s < cmcf->servers.nelts; s++) {    clcf = cscfp[s]->ctx->loc_conf[ngx_http_core_module.ctx_index];    if (ngx_http_init_locations(cf, cscfp[s], clcf) != NGX_OK) {      return NGX_CONF_ERROR;    }    if (ngx_http_init_static_location_trees(cf, clcf) != NGX_OK) {      return NGX_CONF_ERROR;    }  }  if (ngx_http_init_phases(cf, cmcf) != NGX_OK) {    return NGX_CONF_ERROR;  }  if (ngx_http_init_headers_in_hash(cf, cmcf) != NGX_OK) {    return NGX_CONF_ERROR;  }  for (m = 0; ngx_modules[m]; m++) {    if (ngx_modules[m]->type != NGX_HTTP_MODULE) {      continue;    }    module = ngx_modules[m]->ctx;    if (module->postconfiguration) {  // 調用每個 HTTP 模塊的 postconfiguration 回調函數  //  // ngx_http_log_module   ngx_http_log_init  // ngx_http_static_module  ngx_http_static_init  // ngx_http_gzip_static_module  ngx_http_gzip_static_init  // ngx_http_autoindex_module  ngx_http_autoindex_init  // ngx_http_index_module  ngx_http_index_init  // ngx_http_auth_basic_module  ngx_http_auth_basic_init  // ngx_http_access_module  ngx_http_access_init  // ngx_http_limit_conn_module  ngx_http_limit_conn_init  // ngx_http_limit_req_module  ngx_http_limit_req_init  // ngx_http_rewrite_module  ngx_http_rewrite_init  // ngx_http_ssl_module   ngx_http_ssl_init  // ngx_http_write_filter_module  ngx_http_write_filter_init  // ngx_http_header_filter_module ngx_http_header_filter_init  // ngx_http_chunked_filter_module ngx_http_chunked_filter_init  // ngx_http_range_body_filter_module ngx_http_range_body_filter_init  // ngx_http_gzip_filter_module  ngx_http_gzip_filter_init  // ngx_http_postpone_filter_module ngx_http_postpone_filter_init  // ngx_http_ssi_filter_module  ngx_http_ssi_filter_init  // ngx_http_charset_filter_module ngx_http_charset_postconfiguration  // ngx_http_userid_filter_module ngx_http_userid_init  // ngx_http_headers_filter_module ngx_http_headers_filter_init  // ngx_http_copy_filter_module  ngx_http_copy_filter_init  // ngx_http_range_body_filter_module ngx_http_range_body_filter_init  // ngx_http_not_modified_filter_module ngx_http_not_modified_filter_init      if (module->postconfiguration(cf) != NGX_OK) {        return NGX_CONF_ERROR;      }    }  } // 初始化所有的變量 // 不僅包括HTTP core模塊的變量 // 也包括其他的HTTP模塊導出的變量,以及配置文件中使用 set 命令設置的變量 // 這里的初始化包括初始化hash表,以及初始化數組索引  if (ngx_http_variables_init_vars(cf) != NGX_OK) {    return NGX_CONF_ERROR;  }  /*   * http{}'s cf->ctx was needed while the configuration merging   * and in postconfiguration process   */  *cf = pcf; // 初始化 phase_engine 結構  if (ngx_http_init_phase_handlers(cf, cmcf) != NGX_OK) {    return NGX_CONF_ERROR;  }  /* optimize the lists of ports, addresses and server names */ // 創建 http 連接,并設置為監聽狀態  if (ngx_http_optimize_servers(cf, cmcf, cmcf->ports) != NGX_OK) {    return NGX_CONF_ERROR;  }  return NGX_CONF_OK;failed:  *cf = pcf;  return rv;} // }}}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
亚洲香蕉成人av网站在线观看_欧美精品成人91久久久久久久_久久久久久久久久久亚洲_热久久视久久精品18亚洲精品_国产精自产拍久久久久久_亚洲色图国产精品_91精品国产网站_中文字幕欧美日韩精品_国产精品久久久久久亚洲调教_国产精品久久一区_性夜试看影院91社区_97在线观看视频国产_68精品久久久久久欧美_欧美精品在线观看_国产精品一区二区久久精品_欧美老女人bb
国产精品91在线| 欧美成人精品在线| 成人av色在线观看| 成人动漫网站在线观看| 日韩精品在线视频美女| 久久久av免费| 欧美成人精品不卡视频在线观看| 国产精品久久久久秋霞鲁丝| 亚洲欧美日本伦理| 亚洲一区二区三区视频| 亚洲国产私拍精品国模在线观看| 成人免费在线视频网址| 欧美大片在线看| 91在线观看欧美日韩| 欧美精品激情视频| 亚洲美女性生活视频| 欧美视频在线观看免费网址| 亚洲精品在线视频| 亚洲综合中文字幕在线观看| 丁香五六月婷婷久久激情| 日韩欧美综合在线视频| 欧美日韩国产综合视频在线观看中文| 欧美日韩aaaa| 欧美一级视频在线观看| 久久国产精品久久久久| 欧美极品美女视频网站在线观看免费| 日韩在线观看免费高清| 日韩精品中文在线观看| 欧美精品在线免费播放| 国产脚交av在线一区二区| 在线观看国产精品淫| 亚洲片av在线| 国产精品视频色| 国产精品福利网站| 欧美韩日一区二区| 在线免费观看羞羞视频一区二区| 亚洲天堂成人在线视频| 91久久久久久久久久久| 91手机视频在线观看| 91av福利视频| 久久中文精品视频| 91精品久久久久久久久久入口| 午夜精品久久久久久久99黑人| 国产有码在线一区二区视频| 中文字幕日韩av综合精品| 久久影视电视剧凤归四时歌| 国产中文字幕亚洲| 精品高清一区二区三区| 欧美成人午夜免费视在线看片| 伊人伊成久久人综合网小说| 国产精品久久久久久久久久久不卡| 中国日韩欧美久久久久久久久| 国产精品日韩在线| 国产精品精品国产| 久久久久久久国产精品视频| 亚洲欧洲美洲在线综合| 97精品国产97久久久久久免费| 欧美乱人伦中文字幕在线| 欧美亚洲在线观看| 亚洲春色另类小说| 色偷偷88888欧美精品久久久| 欧美日韩精品国产| 97精品国产91久久久久久| 欧美在线不卡区| 欧美成人一区在线| 日韩美女在线观看一区| 久久91亚洲人成电影网站| 欧美理论电影在线播放| 91精品国产色综合久久不卡98| 97在线免费观看| 欧美日韩亚洲高清| 亚洲91精品在线观看| 国产一区深夜福利| 中国日韩欧美久久久久久久久| 成人久久精品视频| 国产精品一区二区三区成人| 国产精品91在线| 久久成人亚洲精品| 97色在线观看免费视频| 精品国产一区二区在线| 亚洲欧美精品伊人久久| 久久久久五月天| 日韩中文字幕视频| 成人黄色在线播放| 国产精品入口日韩视频大尺度| 国产精品日日摸夜夜添夜夜av| 亚洲美腿欧美激情另类| 日韩激情视频在线| 中文字幕久久精品| 2019中文在线观看| 亚洲a中文字幕| 国产精品久久久久久久久久免费| 欧美激情第一页xxx| 亚洲国产成人在线播放| 热久久美女精品天天吊色| 国产精品视频成人| 日韩精品日韩在线观看| 日韩av在线资源| 亚洲一区二区免费在线| 久久av在线播放| 欧美日韩高清在线观看| 亚洲精品中文字幕av| 日韩美女视频中文字幕| 中文字幕亚洲欧美一区二区三区| 奇米4444一区二区三区| 国产精品十八以下禁看| 久久综合九色九九| 97久久精品国产| 久久精品视频免费播放| 亚洲国产成人久久综合一区| 亚洲码在线观看| 亚洲日韩第一页| 日韩精品中文字幕久久臀| 欧美成人剧情片在线观看| 日本sm极度另类视频| 日本国产高清不卡| 亚洲九九九在线观看| 精品亚洲国产视频| 欧美日韩国产91| 欧美日韩在线一区| 黑人精品xxx一区一二区| 亚洲日本欧美日韩高观看| 日韩毛片在线观看| 少妇激情综合网| 亚洲国内高清视频| 色青青草原桃花久久综合| 久久久久日韩精品久久久男男| 日韩av在线免费看| 久久影视电视剧免费网站| 亚洲成av人片在线观看香蕉| 国产精品美女免费| 8050国产精品久久久久久| 久久免费高清视频| 日韩av片永久免费网站| 最近2019年好看中文字幕视频| 亚洲第一区第二区| 亚洲石原莉奈一区二区在线观看| 日本高清不卡在线| 91人成网站www| 国产极品jizzhd欧美| 精品福利在线观看| 日本一区二区不卡| 91成人在线播放| 欧美最猛性xxxx| 亚洲色图18p| 久久精品中文字幕一区| 一本色道久久综合亚洲精品小说| 国产精品女主播| 亚洲成人黄色在线| 亚洲天堂男人的天堂| 国产精品海角社区在线观看| 国产一区二区三区直播精品电影| 久久精品国产久精国产思思| 国产精品久久久久久久美男| 91亚洲一区精品| 精品福利在线看| 国产精品亚洲片夜色在线| 欧美猛交免费看| 精品国产91久久久| 影音先锋日韩有码| 国产精品成人观看视频国产奇米| 日韩中文字幕在线视频| 成人精品一区二区三区电影免费| 久久精品视频免费播放|